【发布时间】:2017-04-25 09:12:55
【问题描述】:
我们正在构建一个 Xamarin Forms 应用,我们注意到我们可以通过在 App.xaml ResourceDictionary 中创建样式以两种方式设置元素的样式
类和 StyleClass 选项
我们将在 App.xaml 中编写
<Style Class="EntryStandard" TargetType="Entry">
<Setter Property="TextColor" Value="#575e62" />
<Setter Property="BackgroundColor" Value="#9facb3" />
<Setter Property="FontSize" Value="14" />
</Style>
然后在这样的内容页面之一中使用它
<Entry StyleClass="EntryStandard" Placeholder="Login Name" Text="{Binding EntryEmailAddress}" />
键和样式选项
这是我们在App.xaml下写的
<Style x:Key="ButtonMainMenu_Purple" TargetType="Button">
<Setter Property="BackgroundColor" Value="#5d4785" />
<Setter Property="FontSize" Value="14" />
<Setter Property="TextColor" Value="#FFFFFF" />
</Style>
然后我们在内容页面中使用以下内容
<Button Style="{StaticResource ButtonMainMenu_Purple}" Text="Friends" Command="{Binding OnFriendsButtonCommand}" />
两者都很好,我只是想知道哪个比另一个更好,为什么?
【问题讨论】:
-
:( 看起来每个人都在圣诞假期......
-
“键和样式选项”对我不起作用。我得到:“找不到关键横幅的静态资源”。我假设样式是在 App.xaml 文件的 Application.Resources 中定义的? “Class and StyleClass 选项”工作正常。
-
这是一篇旧帖子。从那时起,表单发生了很大变化。
标签: xaml styles xamarin.forms