【问题标题】:x:Type missing in UWP - How override base control style?x:UWP 中缺少类型 - 如何覆盖基本控件样式?
【发布时间】:2016-02-07 08:50:14
【问题描述】:

在 WPF 中,我使用以下代码覆盖基本控件样式:

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource  {x:Type Button}}">
    <Setter Property="Padding" Value="5" />
    <Setter Property="Margin" Value="{StaticResource margin}" />
</Style>

在 UWP 中,XAMl 中的 x:Type 消失了。那么如何在 UWP 中完成上述代码呢?谢谢。

【问题讨论】:

    标签: c# .net uwp


    【解决方案1】:

    应该是这样的:

    <Style TargetType="Button">
        <Setter Property="Padding" Value="5" />
        <Setter Property="Margin" Value="{StaticResource margin}" />
    </Style>
    

    【讨论】:

      【解决方案2】:

      根据我从 documentation 收集到的信息,通用 Windows 应用程序不再支持 x:Type

      要绕过样式继承,您需要创建一个具有x:Key 的基本样式,可以使用BasedOn 属性的StaticResource 标记来引用它。

      <Style x:Key="BasicButtonStyle" TargetType="Button">
          ... (This may contain nothing)
      </Style>
      
      <Style TargetType="Button" 
             BasedOn="{StaticResource BasicButtonStyle}">
          ...
      </Style>
      

      【讨论】:

      • Thx ,但是我如何在 Button 的基础上自定义我的 Button?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      • 2019-12-07
      • 1970-01-01
      • 2018-11-22
      • 2021-02-20
      • 1970-01-01
      相关资源
      最近更新 更多