我有一个ListBox
绑定到ObservableCollection<ToDoCategory>
as的控件ItemsSource="{Binding Categories}
。里面ToDoCategory
有CategoryName
and CategoryColor
(两个字符串)。CategoryName
绑定在ItemTemplate
. 现在,我想做的是更改ListBox
基于CategoryColor
. 我已经有要刷的字符串,IValueConverter
它返回SolidColorBrush
字符串。它也在页面资源中正确定义。我知道我需要改变ItemContainerStyle
。目前,我有这样的事情:
<Style x:Key="CategoryListBoxContainerStyle" TargetType="ListBoxItem">
Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border...>
<VisualStateManager.VisualStateGroups>
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding CategoryColor, Converter=StringToBrushConverter}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
.
.
.
</style>
这行不通。如何将 InnerGrid 的背景绑定CategoryColor
到ToDoCategory
?