public class Person
{
private int _Id;
public int Id{get{return value;} set{_Id=value;}}
private string _Code
public string Code{get{return _Code;} set {_Code=value;}}
private string _Name;
public string Name{get{return _Name;}set{_Name=value;}}
}
this is my model class
I have a two Combobox in my form.Combo1 and Combo2.
Combo1 DisplayMember Code ValueMember Id
Combo2 DisplayMember Name ValueMember Id
I want to that when I change the Code or Name another combobox edit value and display value change
I’d recommend several changes:
First, you might want to break your person class out into two classes: Code and Person
Then create a class that you’ll set to your view’s datacontext, normally called a viewmodel in the MVVM design pattern:
Notice that it implements INotifyPropertyChanged. This is crucial with binding in Silverlight. In the constructor of your MainPage.xaml.cs:
Now in your view’s XAMl:
Notice the first combobox binds to the Codes collection on the DataContext. The selectedItem property TWO-WAY binds to the SelectedCode property on the datacontext. When the user changes that selected item, the setter on the datacontext gets called. We updated the list of peopel to show, and raise the PropertyChanged event which notifies the view that it needs to update the people box.
Of course, this would be much cleaner if you properly implemented the MVVM design pattern. I like to use the MVVM Light toolkit for this.
I know that was long-winded, but I wanted to guide you down a correct path so you could use this knowledge on this project and in the future 🙂