【发布时间】:2015-10-27 03:36:16
【问题描述】:
我正在尝试实现与 CSS 样式等效的 XAML。我想为 ContentPage 创建一个自定义布局,我可以在我的应用程序的所有页面中使用它,并且每个平台都有不同的值。
具体来说,我从自定义填充开始:我正在尝试将此代码放在我的 App.xaml 文件中:
<Application.Resources>
<ResourceDictionary>
<OnPlatform x:Key="MyPadding"
x:TypeArguments="Thickness"
iOS="0, 20, 0, 0"
Android="0, 0, 0, 0"/>
<Style
x:Key="labelGreen"
TargetType="Entry">
<Setter
Property="TextColor"
Value="Green"/>
</Style>
</ResourceDictionary>
</Application.Resources>
在单独的 ContentPage 中,我正在执行以下操作,但它不起作用:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.LoginScreen"
Style="{DynamicResource MyPadding}"
>
自定义条目样式工作正常。但填充没有。我收到错误消息:“SetValue: Can not convert Xamarin.Forms.OnPlatform`1[Xamarin.Forms.Thickness] to type 'Xamarin.Forms.Style'”
我做错了什么?
【问题讨论】:
标签: c# css xaml cross-platform xamarin.forms