Wpf 对组合框和文本框使用样式
是否有一种方法可以为多个Wpf 对组合框和文本框使用样式,wpf,Wpf,是否有一种方法可以为多个TargetType重复使用样式,例如ComboBox和TextBox <Style TargetType="ComboBox, TextBox" /> 有这样的事吗?或者,唯一的方法是复制样式并将每个样式指向不同的类型吗?相反,您可以提供targettype作为控件,定义setter控件项目,并将该样式应用于textbox和combox。相反,您可以提供targettype作为控件,定义setter控件项目,并将该样式应用于文本框和组合框。你不能(如果
TargetType
重复使用样式,例如ComboBox和TextBox
<Style TargetType="ComboBox, TextBox" />
有这样的事吗?或者,唯一的方法是复制样式并将每个样式指向不同的类型吗?相反,您可以提供targettype作为控件,定义setter控件项目,并将该样式应用于textbox和combox。相反,您可以提供targettype作为控件,定义setter控件项目,并将该样式应用于文本框和组合框。你不能(如果我没弄错的话)。 但是为了避免复制粘贴,您可以使用一个键创建一个BaseStyle,然后为ComboBox和TextBox创建两个基于BaseStyle的样式。smth是这样的:
<Style x:Key="BaseStyle" TargetType="{x:Type Control}">
<Setter ... />
</Style>
<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type ComboBox }" />
<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type TextBox}" />
你不能(如果我没弄错的话)。
但是为了避免复制粘贴,您可以使用一个键创建一个BaseStyle,然后为ComboBox和TextBox创建两个基于BaseStyle的样式。smth是这样的:
<Style x:Key="BaseStyle" TargetType="{x:Type Control}">
<Setter ... />
</Style>
<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type ComboBox }" />
<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type TextBox}" />