【问题标题】:Xamarin Forms Styling using StyleClass vs Style attribute使用 StyleClass 与 Style 属性的 Xamarin 表单样式
【发布时间】: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


【解决方案1】:

常规样式遵循标准的、相对不灵活的 WPF 模型。样式类包括级联语义并且是新的theme 支持的一部分。然而,它们的文档记录很差,并且仍处于测试阶段。

【讨论】:

  • 是的。我发现我无法使用当前的 Beta 主题发布构建。所以要小心。
猜你喜欢
  • 1970-01-01
  • 2018-01-10
  • 2017-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
相关资源
最近更新 更多