C# WPF如何设置组合框的背景
嗨,我有一个问题,我有一个组合框,我可以用它选择一种颜色C# WPF如何设置组合框的背景,c#,wpf,combobox,C#,Wpf,Combobox,嗨,我有一个问题,我有一个组合框,我可以用它选择一种颜色 <ComboBox Name="cb_farbe" Text="farbe" HorizontalContentAlignment="Center" IsEditable="True" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" Grid.ColumnSpan="2" SelectionChanged="FarbeSelected"> <
<ComboBox Name="cb_farbe" Text="farbe" HorizontalContentAlignment="Center" IsEditable="True" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" Grid.ColumnSpan="2" SelectionChanged="FarbeSelected">
<ComboBox.ItemTemplate>
<DataTemplate>
<Rectangle Name="rectangle_farbecontent" Width="425" Height="20" Fill="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<SolidColorBrush>Blue</SolidColorBrush>
<SolidColorBrush>Green</SolidColorBrush>
<SolidColorBrush>LightBlue</SolidColorBrush>
<SolidColorBrush>Black</SolidColorBrush>
<SolidColorBrush>LightGray</SolidColorBrush>
<SolidColorBrush>Gray</SolidColorBrush>
</ComboBox>
不要设置
IsEditable
和Text
属性
并且不要更改SelectionChanged处理程序中的组合框属性。请改用适当的数据模板
<ComboBox HorizontalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<Rectangle Width="425" Height="20" Fill="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<SolidColorBrush>Blue</SolidColorBrush>
<SolidColorBrush>Green</SolidColorBrush>
<SolidColorBrush>LightBlue</SolidColorBrush>
<SolidColorBrush>Black</SolidColorBrush>
<SolidColorBrush>LightGray</SolidColorBrush>
<SolidColorBrush>Gray</SolidColorBrush>
</ComboBox>
蓝色
绿色
淡蓝色
黑色
浅灰色
灰色
不要设置IsEditable
和Text
属性
并且不要更改SelectionChanged处理程序中的组合框属性。请改用适当的数据模板
<ComboBox HorizontalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<Rectangle Width="425" Height="20" Fill="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<SolidColorBrush>Blue</SolidColorBrush>
<SolidColorBrush>Green</SolidColorBrush>
<SolidColorBrush>LightBlue</SolidColorBrush>
<SolidColorBrush>Black</SolidColorBrush>
<SolidColorBrush>LightGray</SolidColorBrush>
<SolidColorBrush>Gray</SolidColorBrush>
</ComboBox>
蓝色
绿色
淡蓝色
黑色
浅灰色
灰色
不要设置文本属性。你到底想显示什么?@Clemens我希望它只填充一种颜色,而不是在用户选择颜色后显示字符串。不要设置文本属性。你到底想显示什么?@Clemens我希望在用户选择一种颜色后用颜色填充它,而不是显示字符串。我在另一个答案中已经说过了。使用SelectedItem或SelectValue和SelectedValuePath。我在另一个答案中已经说过了。使用SelectedItem或SelectValue和SelectedValuePath。