如何在嵌套网格中设置 TextBlock 的前景?
How to set Foreground of a TextBlock in a nested grid?
我在 Grid
中有一个 TextBlock
,它在 MaterialDesignInXaml
提供的 PopupBox
中,示例结构:
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
<materialDesign:PopupBox>
<Grid>
<TextBlock Text="Foo" />
</Grid>
</materialDesign:PopupBox>
我正在尝试将 TextBlock
前景应用为 App.xaml
中的全局资源:
<Style TargetType="materialDesign:PopupBox">
<Setter Property="TextBlock.Foreground" Value="red" />
</Style>
但似乎没有用,有什么帮助吗?
您需要为 Grid
定义一个隐含的 Style
。试试这个:
<Style TargetType="materialDesign:PopupBox">
<Style.Resources>
<Style TargetType="Grid">
<Setter Property="TextElement.Foreground" Value="Red" />
</Style>
</Style.Resources>
</Style>
我在 Grid
中有一个 TextBlock
,它在 MaterialDesignInXaml
提供的 PopupBox
中,示例结构:
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
<materialDesign:PopupBox>
<Grid>
<TextBlock Text="Foo" />
</Grid>
</materialDesign:PopupBox>
我正在尝试将 TextBlock
前景应用为 App.xaml
中的全局资源:
<Style TargetType="materialDesign:PopupBox">
<Setter Property="TextBlock.Foreground" Value="red" />
</Style>
但似乎没有用,有什么帮助吗?
您需要为 Grid
定义一个隐含的 Style
。试试这个:
<Style TargetType="materialDesign:PopupBox">
<Style.Resources>
<Style TargetType="Grid">
<Setter Property="TextElement.Foreground" Value="Red" />
</Style>
</Style.Resources>
</Style>