【发布时间】:2018-05-16 17:28:33
【问题描述】:
当我添加此代码时,我正在尝试在 Combobox 中添加一个彩色椭圆:
<ComboBox Width="300" BorderBrush="#6593CF" Visibility="Visible" BorderThickness="1" Margin="5" VerticalAlignment="Top" ItemsSource="{Binding Parts}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0">
<Label Content="Code" Margin="0" Padding="0"/>
<Label Content="{Binding reference}" Margin="0" Padding="0"></Label>
<Label Content=" R " Margin="0" Padding="0"/>
<Label Content="{Binding R}" Margin="0" Padding="0"></Label>
<Ellipse Height="20" Width="20" Fill="Red" Margin="0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
它可以工作并显示红色椭圆;但是当我像这样绑定 Ellipse 的 Fill 属性时:
<Ellipse Name="elli" Height="20" Width="20" Fill="{Binding color}" Margin="0"/>
并在 ViewModel 中添加颜色属性,它不起作用并在组合框中显示一个空白区域。
ViewModel 中的属性代码如下:
public string _color = "Red";
public string color
{
get
{
return _color;
}
set
{
if (_color == value)
{
return;
}
_color = value;
RaisePropertyChanged("color");
}
}
我也尝试在 Datagrid 元素中添加 Ellipse,但我遇到了同样的问题。
【问题讨论】: