Silverlight updating my source objects, how to update my UI
I have a small silverlight app, where i have a list of objects with a Name and a Description. I databind them to a listbox, and show them, no problems.
However i want to be able to change the name or the description from my codebehind (updated through a webservice) and make the UI update, how to make the ui reflect the change of e.g. my name?
EDIT: Made the binding twoway, implemented the interface INotifyPropertyChanged interface, still not working. Debugging shows that the PropertyChanged event is not assigned
public string Name
{
get
{
return name;
}
set
{
开发者_如何学C OnPropertyChanged("Name");
}
}
and the OnPropertyChanged method
private void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
I never get into the 'if', the event is null i.e. not assigned by anyone ???
SOLUTION: Updated the setter to use the instance variable of 'name', tried it first with the property 'Name' this gave a stackoverflow :-)
Make the binding mode to be TwoWay
. See here: http://msdn.microsoft.com/en-us/library/cc278072%28VS.95%29.aspx#direction_of_the_data_flow
精彩评论