Hi all,
I have this issue with ComboBox that uses IEnumerable<Brush>
as ItemsSource; the problem lies when I (programmatically) try to set SelectedItem. Here is the code that describes the problem:
private readonly List<Brush> colors_;
private Brush white_;
ViewModelConstructor()
{
colors_ = (from p in brushes_type.GetProperties()
select (Brush)converter.ConvertFromString(p.Name)).ToList();
white_ = colors_.Single(b => b.ToString() == "#FFFFFFFF");
}
public IEnumerable<Brush> Colors
{
get { return colors_; }
}
public Brush White
{
get { return white_; }
set
{
if (white_ != value)
white_ = value;
}
}
And here is xaml code:
<ComboBox ItemsSource="{Binding Path=Colors}"
SelectedItem="{Binding Path=White}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderThickness="1"
BorderBrush="Black"
Width="20"
Height="12"
SnapsToDevicePixels="True"
Margin="0,0,4,0">
<Border Background="{Binding}"/>
</Border>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
After the get on the White property is called I get an Exception: Cannot set a property on object '#FFFFFFFF' because it is in a read-only state. If i leave White (white_) as null, everything works just fine.