改变ListBoxItem中的文本色彩
改变ListBoxItem中的文本颜色
我的ListBoxItem上有一个TextBlock和一个Button,当ListBoxItem被选中后,我希望TextBlock和Button中的文本颜色都要发生变化,可我试了,只有TextBlock颜色变了,Button没有变化。
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="{TemplateBinding Background}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
</ContentPresenter>
</Border>
<Button Grid.Column="1" Margin="10,0,0,0">aaa</Button>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="ListBoxItem.IsSelected" Value="true">
<Setter Property="ListBoxItem.Foreground" Value="#ffff0000"/>
</Trigger>
<Trigger Property="ListBoxItem.IsSelected" Value="false">
<Setter Property="ListBoxItem.Foreground" Value="#ff000000"/>
</Trigger>
</Style.Triggers>
</Style>
------解决思路----------------------
<Button Grid.Column="1" Margin="10,0,0,0" Foreground="{TemplateBinding Foreground}">aaa</Button>
我的ListBoxItem上有一个TextBlock和一个Button,当ListBoxItem被选中后,我希望TextBlock和Button中的文本颜色都要发生变化,可我试了,只有TextBlock颜色变了,Button没有变化。
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="{TemplateBinding Background}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
</ContentPresenter>
</Border>
<Button Grid.Column="1" Margin="10,0,0,0">aaa</Button>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="ListBoxItem.IsSelected" Value="true">
<Setter Property="ListBoxItem.Foreground" Value="#ffff0000"/>
</Trigger>
<Trigger Property="ListBoxItem.IsSelected" Value="false">
<Setter Property="ListBoxItem.Foreground" Value="#ff000000"/>
</Trigger>
</Style.Triggers>
</Style>
------解决思路----------------------
<Button Grid.Column="1" Margin="10,0,0,0" Foreground="{TemplateBinding Foreground}">aaa</Button>