所以,我在列表框中有一个网格。The purpose is that when the listboxitem is selected, I want the grid to show, having the selected item expand to show more detail information. 我为此设置了一个样式触发器,它工作得很好,除了一件事:标签和文本块样式未在网格上应用。
我假设这与折叠的列表框项的默认状态有关,因此 wpf 会跳过样式,我希望它会在选择触发时将它们打开,但事实并非如此。如果我在每个标签/文本块上使用 Style="{StaticResource Mystyle}" ,它的样式很好,它似乎没有像应用程序中其他地方的可见网格那样执行继承的样式魔法。请参阅下面的代码,当网格出现时,标签不会显示为粗体或任何内容。
<Style TargetType="{x:Type Grid}" x:Key="ListBoxItemCollapseGrid">
<Style.Triggers>
<DataTrigger Binding="{Binding
Path=IsSelected,
RelativeSource=
{
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListBoxItem}
}
}"
Value="False">
<Setter Property="Grid.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
<Style.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="{StaticResource BaseText}" />
<Setter Property="Padding" Value="3,0,0,0" />
</Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{StaticResource BaseText}" />
</Style>
</Style.Resources>
</Style>