开发者

WPF Dynamic Nested Binding

Suppose I have a view with the following control (DataCon开发者_如何学Gotext is properly set to a view model that implements INotify):

When the view is first shown, Document is non existant (null). During runtime (after the user opens a Document), then Document and dependent structure (including Document.SelectedFrame.Image) is created.

At that point, I do invoke the PropertyChaned handler of my SelectedFrame object (which also implements INotifyProperty), but nothing happens.

Do I have to re-tie the bindings at runtime when Document gets created?


I assume you have a binding which looks something like this:

<Image Source="{Binding Path=Document.SelectedFrame.Image}"></Image>

You need to raise PropertyChanged on the ViewModel class when the value of Document changes. It should look something like this:

public object Document
{
    get { return document; }
    set
    {
        document = value;
        this.PropertyChanged(this, new PropertyChangedEventArgs("Document"));
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜