我有一个ListBox绑定到ObservableCollection<ToDoCategory>as的控件ItemsSource="{Binding Categories}。里面ToDoCategory有CategoryNameand 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?