我正在尝试在 Xaml 中的不同平台上呈现设备特定 View 。
查看this link我可以看到我可以在 Xaml 中使用 Device.OnPlatform
设置属性,如下所示:
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key=”standardFont” x:TypeArguments=”Font”>
<OnPlatform.iOS>12</OnPlatform.iOS>
<OnPlatform.Android>12</OnPlatform.Android>
<OnPlatform.WinPhone>18</OnPlatform.WinPhone>
</OnPlatform>
</ResourceDictionary>
</ContentPage.Resources>
但我想像这样在每个平台上设置 View :
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key=”NumericTextBox” x:TypeArguments=”View”>
<OnPlatform.iOS><sf:NumericTextBox/></OnPlatform.iOS>
<OnPlatform.Android><sf:NumericTextBox/></OnPlatform.Android>
<OnPlatform.WinPhone><Entry/></OnPlatform.WinPhone>
</OnPlatform>
</ResourceDictionary>
</ContentPage.Resources>
我需要这个的原因是因为 Syncfusion NumericTextBox
在 Windows 上不起作用(我已经报告了这个错误,但这是一个解决方法)
这可能吗?
PS. 我知道自定义渲染器,但在这种情况下,因为 Syncfusion 数字文本框已经有一个自定义渲染器,所以我不能使用这种技术
最佳答案
你几乎拥有它。你只需要使用一个 ContentView 将其内容属性设置为您的静态资源。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XFApp3.Page1">
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key=”NumericTextBox” x:TypeArguments=”View”>
<OnPlatform.iOS><sf:NumericTextBox/></OnPlatform.iOS>
<OnPlatform.Android><sf:NumericTextBox/></OnPlatform.Android>
<OnPlatform.WinPhone><Entry/></OnPlatform.WinPhone>
</OnPlatform>
</ResourceDictionary>
</ContentPage.Resources>
<!-- That's the line you are missing -->
<ContentView Content="{StaticResource NumericTextBox}" ></ContentView>
</ContentPage>
您已准备好输入一些数字。
关于c# - 我可以在 Xaml 中使用 Device.OnPlatform 设置设备特定 View 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37611219/