Xamarin 表单 - 将 XAML 转换为 C#
Xamarin forms - Convert XAML to c#
我在 XAML 中定义了一个 ResourceDictionary
,我想将其转换为 C#。
我无法转换 OnPlatform
属性 和转换器 属性。
如何转换?
<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" />
对于在线平台,只要使用 VolosIconFont,您就可以使用此代码段:
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# 转换器的参考 class。您不需要将其映射到 C#。它已经在那里了。
只要您想使用转换器,您只需以编程方式设置绑定:
例如
myLabel.SetBinding(myLabelProperty, new Binding("MyC#Property", null, new SelectedItemChangedEventArgsConverter(), null, null));
不确定您为什么要这样做,但对我来说这似乎是错误的方法。尝试坚持 xaml。更简单!
我在 XAML 中定义了一个 ResourceDictionary
,我想将其转换为 C#。
我无法转换 OnPlatform
属性 和转换器 属性。
如何转换?
<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" />
对于在线平台,只要使用 VolosIconFont,您就可以使用此代码段:
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# 转换器的参考 class。您不需要将其映射到 C#。它已经在那里了。 只要您想使用转换器,您只需以编程方式设置绑定: 例如
myLabel.SetBinding(myLabelProperty, new Binding("MyC#Property", null, new SelectedItemChangedEventArgsConverter(), null, null));
不确定您为什么要这样做,但对我来说这似乎是错误的方法。尝试坚持 xaml。更简单!