Hello,
I have a very simple combobox that has a source of type ObservableCollection<String>. The combobox is bound to a property of an entity object (Event.WaveDuration) that is of type int. Everything works great but when I open the form to edit the entity, I cannot figure out how to get the combobox to initially display the value that is stored in the Event.WaveDuration property. The combobox comes up blank (though the dropdown displays the collection just fine) and if I select a different value from the list, it is saved properly to the database. So I know the binding is working since the save is working properly.
I have tried many things (thinking I did not need to use the SelectedItem property in xaml but since that didn't work I assumed I needed it to convert the int to a string). I have tried to use ObservableCollection<int> as well with the same results.
So my issue is trying to display the value in Event.WaveDuration when the form initially opens..
Here is my code thus far:
XAML:
MVVM:
Thank you in advance!
I have a very simple combobox that has a source of type ObservableCollection<String>. The combobox is bound to a property of an entity object (Event.WaveDuration) that is of type int. Everything works great but when I open the form to edit the entity, I cannot figure out how to get the combobox to initially display the value that is stored in the Event.WaveDuration property. The combobox comes up blank (though the dropdown displays the collection just fine) and if I select a different value from the list, it is saved properly to the database. So I know the binding is working since the save is working properly.
I have tried many things (thinking I did not need to use the SelectedItem property in xaml but since that didn't work I assumed I needed it to convert the int to a string). I have tried to use ObservableCollection<int> as well with the same results.
So my issue is trying to display the value in Event.WaveDuration when the form initially opens..
Here is my code thus far:
XAML:
<
telerikInput:RadComboBox
ItemsSource
=
"{Binding WaveDurations}"
SelectedItem
=
"{Binding SelectedWaveDuration, Mode=TwoWay}"
SelectedValue
=
"{Binding Event.WaveDuration, Mode=TwoWay}"
>
</
telerikInput:RadComboBox
>
MVVM:
public ObservableCollection<
string
> WaveDurations {
get {
if (_waveDurations == null) {
_waveDurations = new ObservableCollection<
string
> {"10", "15", "20", "30"};
SelectedWaveDuration = this.Event.WaveDuration.ToString();
}
return _waveDurations;
}
}
public string SelectedWaveDuration
{
get { return _selectedWaveDuration; }
set {
_selectedWaveDuration = value;
this.OnPropertyChanged(m => m.SelectedWaveDuration);
}
}
Thank you in advance!