我有这个列表框样式,但由于某种原因,我无法根据触发器更改前景色。我想在选择列表框中的项目时将前景色更改为黑色。我搜遍了所有的解决方案似乎并不适用于我的情况。这里是我的列表框...使用触发器更改ListBoxItem.Foreground颜色
<ListBox IsSynchronizedWithCurrentItem="True" SelectedValuePath="RecordId" ItemsSource="{Binding People}" SelectedValue="{Binding SelectedPersonId}" HorizontalAlignment="Stretch" Margin="20,5,10,5" Width="Auto" Grid.Row="1" Background="{x:Null}" BorderBrush="{x:Null}" x:Name="lstCustomers">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="Auto" Width="Auto" d:DesignWidth="545.375" d:DesignHeight="50.294">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="132.375"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="stackPanel" Orientation="Horizontal" HorizontalAlignment="Stretch">
<Label FontSize="16" Content="{Binding FullName}" Foreground="White"/>
<Label FontSize="16" Content="{Binding DisplayName}" Margin="5,0,0,0" Foreground="White"/>
</StackPanel>
<DockPanel LastChildFill="True" HorizontalAlignment="Stretch" Margin="0" Grid.Column="1">
<Label Content="{Binding Date}" ContentStringFormat="yyyy/MM/dd" FontSize="24" HorizontalAlignment="Right" Foreground="White" DockPanel.Dock="Right" VerticalAlignment="Center"/>
</DockPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border BorderBrush="#26FFFFFF" BorderThickness="3" CornerRadius="5" Name="Border" Margin="0,0,2,3" Padding="0" SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="#7FFFFFFF" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="#0FFFFFFF"></Setter>
<Setter TargetName="Border" Property="BorderBrush" Value="#BEFFFFFF"></Setter>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelected" Value="true"></Condition>
<Condition Property="IsMouseOver" Value="true"></Condition>
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background" Value="#7FFFFFFF"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
任何帮助,将不胜感激!
谢谢!
? – 2012-02-09 18:26:16
是的,这是正确的。问题是我无法在边框控件上设置前景,所以我不知道如何在模板中设置引用数据模板中实际项目的样式... – Lukasz 2012-02-09 19:49:08