Apply an application-level style to all textboxes

前端 未结 1 1299
野趣味
野趣味 2020-12-17 09:04

How do I apply a style defined in my Application.xaml to all the textboxes in a particular window? I don\'t want to type Style=\"{StaticResource MyStyle}\" with

相关标签:
1条回答
  • 2020-12-17 09:17

    Then just add the Style to your App.Xaml or your Theme.xaml (if you have one) or even your Window.Resources if you just have 1 Window, just make sure you don't set the x:Key

    Example:

    This will apply to all TextBoxes(no x:Key)

    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Foreground" Value="Red" />
    </Style>    
    

    TextBoxes will have to use Style="{StaticResource MyStyle}" to use this :

    <Style x:Key="MyStyle" TargetType="{x:Type TextBox}">
        <Setter Property="Foreground" Value="Red" />
    </Style>    
    
    0 讨论(0)
提交回复
热议问题