如何将在Application.xaml中定义好的样式应用到特定窗口中的所有文本框?我不想在每个文本框中都打上Style="{StaticResource MyStyle}"
,因为它们多达几十个。这是使用WPF和VS2010。
接下来只需将Style
添加到您的App.Xaml
或Theme.xaml
(如果有),甚至是您的Window.Resources
(如果只有一个Window
),只需确保不设置x:Key
例如:
这将适用于所有的TextBoxes
(没有x:Key)
<Style TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Red" />
</Style>
TextBoxes需要使用Style="{StaticResource MyStyle}"
才能使用此功能:
<Style x:Key="MyStyle" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Red" />
</Style>