How do I set the foreground color of any child element in a Grid from the Grid's style?

前端 未结 2 1130
感情败类
感情败类 2021-02-13 13:53

How do I set the Foreground color of all child elements in a Grid from within the Grid\'s Style? I know I\'ve done this before, but I can\'t remember w

相关标签:
2条回答
  • 2021-02-13 14:18

    Figured it out, I just need to set the default style in <Style.Resources>

    <Style x:Key="MyGridStyle" TargetType="{x:Type Grid}">
        <Style.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Foreground" Value="Red" />
            </Style>
            <Style TargetType="{x:Type TextBox}">
                <Setter Property="Foreground" Value="Red" />
            </Style>
        </Style.Resources>
    </Style>
    
    0 讨论(0)
  • 2021-02-13 14:24

    How about:

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