【问题标题】:WinUI UWP - How to create a custom style that inherits from it?WinUI UWP - 如何创建继承自它的自定义样式?
【发布时间】:2020-10-26 12:24:21
【问题描述】:

我已经为 WinUI 添加了 nuget 包,并在 App.xaml 中添加了合并的字典,并且对于不受 Style 指令影响的所有控件,确实会出现新样式。然而,Style 的简单使用会导致 Style 的设置器应用于原始 UWP 模板而不是 WinUI 模板。例如这段代码:

    <Grid.Resources>
        <Style TargetType="ComboBox">
            <Setter Property="Width" Value="160"/>
        </Style>
    </Grid.Resources>

将导致组合框出现没有圆角半径和比不应用上述情况时更厚的边框。

有什么解决办法吗?

【问题讨论】:

    标签: xaml uwp winui


    【解决方案1】:

    要覆盖 WinUI 样式的属性,您可以使用 based-on styles

    因此,在您的具体情况下,您可以执行以下操作:

    <Style TargetType="ComboBox" BasedOn="{StaticResource DefaultComboBoxStyle}">
        <Setter Property="Width" Value="160"/>
    </Style>
    

    这样,您将创建一个基于 WinUI 样式(称为 DefaultComboBoxStyle)的新样式,您可以在其中覆盖 width 属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2020-12-01
      • 2016-10-11
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      相关资源
      最近更新 更多