我有一個ComboBox,其ItemSource是MyClass的ListCollectionView。組合框使用下面的ItemTemplate:在DataTemplate/ItemTemplate中綁定
<Style x:Key="StyleComboBoxGroups" BasedOn="{StaticResource BaseComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<BulletDecorator VerticalAlignment="Center">
<BulletDecorator.Bullet>
<Ellipse Margin="3,0,0,0" Width="4" Height="4"/>
</BulletDecorator.Bullet>
<TextBlock Margin="3,0,0,0" Style="{StaticResource BaseTextBlock}" Text="{Binding}"/>
</BulletDecorator>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
MyClass的暴露了兩個屬性:
公共密封類MyClass的 { 公共MyEnum Property1 {獲得;組; } public String Property2 {get;組; } }
我想弄清楚如何使TextBlock.Foreground顏色取決於Property1。目前我試過這些無濟於事:
Foreground="{Binding Property1, Converter=MyEnumToColorConverter}"
Foreground="{Binding Converter=MyEnumToColorConverter, Path=Property1}"
Foreground="{Binding Converter=MyEnumToColorConverter, Path=Property1, Source={Binding}}"
但我總是得到一個異常。我如何正確綁定到ComboBox項目?