开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜