I have ComboBoxwhat it looks like:
<ComboBox
ItemsSource="{Binding JobList}"
SelectedValue="{Binding Job,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
DisplayMemberPath="Title"
SelectedValuePath="Id"
IsEditable="True"
StaysOpenOnEdit="True"
/>
and its binding to mine ViewModel, which is as follows:
public class ViewModel {
public Job Job {
get { return _job; }
set {
if(value == _job) return;
_job = value;
OnPropertyChanged( () => Job );
}
}
public ObservableCollection<Job> JobList
{ }
}
and Job:
public class Job {
public int Id { get; set; }
public string Title { get; set; }
}
Indeed, I want to populate the list with ComboBoxassignment. Therefore, if the user specified Jobin the list, the user can select it from the list, otherwise he enters a new one Job.Titlein ComboBox, the view model notifies about it and creates a new element Job, and also add it to JobList.
Do you have any ideas? Could you help me?
source
share