1 回答

TA貢獻1809條經驗 獲得超8個贊
您應該編寫一個IValueConverter
從您的轉換PathState
為相應的System.Windows.Media.Brush
.?使用預定義的Brushes
,除非您需要特殊的東西。
然后在資源中的某個位置實例化值轉換器(可以在任何父級別,我僅將其放入ComboBox
本示例中。然后使用轉換器將顏色綁定到顯示屬性。
如果你想要Background
,就在 之內做ItemContainerStyle
。如果你想把Foreground
它放在需要的地方。注意:我的示例設置了 Foreground=Background,你不會看到太多。
<ComboBox>
? ? <ComboBox.Resources>
? ? ? ? <local:MyColorConverter x:Key="colorConverter"/>
? ? </ComboBox.Resources>
? ? <ComboBox.ItemTemplate>
? ? ? ? <DataTemplate>
? ? ? ? ? ? <TextBlock Text="{Binding PathID}" Foreground="{Binding PathState,Converter={StaticResource colorConverter}}"/>
? ? ? ? </DataTemplate>
? ? </ComboBox.ItemTemplate>
? ? <ComboBox.ItemContainerStyle>
? ? ? ? <Style TargetType="ComboBoxItem">
? ? ? ? ? ? <Setter Property="Background" Value="{Binding PathState,Converter={StaticResource colorConverter}}"/>
? ? ? ? </Style>
? ? </ComboBox.ItemContainerStyle>
</ComboBox>
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報