x:Type 在 UWP 中丢失 - 如何覆盖基本控件样式? [英] x:Type missing in UWP - How override base control style?
本文介绍了x:Type 在 UWP 中丢失 - 如何覆盖基本控件样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 WPF 中,我使用以下代码覆盖基本控件样式:
in WPF I override the basic control styles with the following Code:
<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中完成以上代码呢?谢谢.
In UWP the x:Type
in XAMl is gone. So how can I accomplish the above code in UWP? Thanks.
推荐答案
我可以从 文档,通用 Windows 应用不再支持 x:Type
.
From what I can gather from the documentation, x:Type
is no longer supported in Universal Windows Apps.
要绕过样式继承,您需要创建一个具有 x:Key
的基本样式,可以使用 StaticResource
标记来引用 >BasedOn
属性.
To get around style inheritance, you will need to create a base style which has an x:Key
, this can be referenced using the StaticResource
markup for the BasedOn
property.
<Style x:Key="BasicButtonStyle" TargetType="Button">
... (This may contain nothing)
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource BasicButtonStyle}">
...
</Style>
这篇关于x:Type 在 UWP 中丢失 - 如何覆盖基本控件样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文