x:Type UWP 中缺少 - 如何覆盖基本控件样式?
x:Type missing in UWP - How override base control style?
在 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 中完成上述代码呢?谢谢
应该是这样的:
<Style TargetType="Button">
<Setter Property="Padding" Value="5" />
<Setter Property="Margin" Value="{StaticResource margin}" />
</Style>
根据我从 documentation 收集到的信息,通用 Windows 应用程序不再支持 x:Type
。
要绕过样式继承,您需要创建一个具有 x:Key
的基本样式,可以使用 BasedOn
[=21] 的 StaticResource
标记来引用它=].
<Style x:Key="BasicButtonStyle" TargetType="Button">
... (This may contain nothing)
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource BasicButtonStyle}">
...
</Style>
在 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 中完成上述代码呢?谢谢
应该是这样的:
<Style TargetType="Button">
<Setter Property="Padding" Value="5" />
<Setter Property="Margin" Value="{StaticResource margin}" />
</Style>
根据我从 documentation 收集到的信息,通用 Windows 应用程序不再支持 x:Type
。
要绕过样式继承,您需要创建一个具有 x:Key
的基本样式,可以使用 BasedOn
[=21] 的 StaticResource
标记来引用它=].
<Style x:Key="BasicButtonStyle" TargetType="Button">
... (This may contain nothing)
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource BasicButtonStyle}">
...
</Style>