【问题标题】:Xamarin forms - Convert XAML to c#Xamarin 表单 - 将 XAML 转换为 c#
【发布时间】:2019-02-27 09:24:13
【问题描述】:

我在 XAML 中定义了一个 ResourceDictionary,我想将其转换为 c#。

我无法转换 OnPlatform 属性和 Converters 属性。

如何转换?

<OnPlatform x:Key="VolosIconFont" x:TypeArguments="x:String">
    <On Platform="iOS" Value="VolosIconFont" />
    <On Platform="Android" Value="Fonts/VolosIconFont.ttf#VolosIconFont" />
    <On Platform="UWP, WinPhone" Value="Assets/Fonts/VolosIconFont.ttf#VolosIconFont" />
</OnPlatform>

还有这个?

<core:SelectedItemChangedEventArgsConverter x:Key="SelectedItemChangedEventArgsConverter" />

【问题讨论】:

    标签: c# xaml xamarin.forms resourcedictionary


    【解决方案1】:

    对于 onplatform,您可以在使用 VolosIconFont 时使用此 sn-p:

    switch(Device.RuntimePlatform)
    {
        case Device.iOS:
        //reference your xaml item and apply your changes.
            break;
        case Device.Android:
            break;
        case Device.UWP:   
            break;
        case Device.macOS:
            break;
    }
    

    查看转换器,您发布的那一行只是 C# Converter 类的引用。您不需要将其映射到 C# 中。它已经在那里了。 每当您想使用转换器时,您只需要以编程方式设置绑定: 例如

    myLabel.SetBinding(myLabelProperty, new Binding("MyC#Property", null, new SelectedItemChangedEventArgsConverter(), null, null));
    

    不确定您为什么要这样做,但对我来说这似乎是错误的方法。尝试坚持使用 xaml。更简单!

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多