【发布时间】:2020-07-06 12:39:38
【问题描述】:
我一直在使用 Xamarin.Forms 应用程序,我注意到我有两个应用样式的选项。我可以创建一个具有“类”属性的样式,并将其与元素“StyleClass”属性一起使用,如下所示:
<Style Class="GenericButton" TargetType="Button">
<Setter Property="BackgroundColor" Value="Orange"/>
</Style>
<Button StyleClass="GenericButton" Command="{Binding LoginCommand}" Text="Login" />
或者,我可以编写一个带有“x:Key”的样式并将其与设置为静态资源的“样式”属性一起使用:
<Style x:Key="GenericBut" TargetType="Button">
<Setter Property="BackgroundColor" Value="Azure"/>
</Style>
<Button Style="{StaticResource GenericBut}" Command="{Binding LoginCommand}" Text="Login" />
其中任何一个似乎都有效,但我不知道一般使用哪个,而且我找不到关于它们用途的适当文档。 StyleClass 是一个 IList,我相信它会应用 CSS 之类的样式,这看起来很有用,但我想知道一直使用它是否会产生无法预料的后果。
谢谢
【问题讨论】:
标签: xaml user-interface xamarin.forms