I have a control,where is combox. I bind to it properties from modelview. I can bind properties to textboxes, but not to combobox. Value from modelview is 4. Anyone know why is that ?
<ComboBox HorizontalAlignment="Left" VerticalAlignment="Top" SelectedItem="{Binding Path=QuantityOfStars}">
<ComboBoxItem Content="0"></ComboBoxItem>
<ComboBoxItem Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
<ComboBoxItem Content="4"></ComboBoxItem>
<ComboBoxItem Content="5"></ComboBoxItem>
</ComboBox>
public int QuantityOfStars
{
get
{
return this.ReporterHotelDescription.QuantityOfStars;
}
set
{
this.ReporterHotelDescription.QuantityOfStars = value;
NotifyChanged("QuantityOfStars");
}
}
You filled your ComboBox with ComboBoxItems, not integers, so it cannot convert them to an integer to bind to your property. Either fill the ComboBox with integers manually:
Or, bind the
ItemsSourceproperty on the ComboBox to a property in your ViewModel that is a list of the appropriate integers.