开发者

WPF InotifyPropertyChanged and view models

So I think I'm doing something pretty basic. I know why this doesn't work, but it seems like there should be a straight foward way to make it work.

code:

private string fooImageRoot;
 // ....
 pub开发者_JAVA技巧lic BitmapImage FooImage
 {
  get
  {
   URI imageURI = new URI(Path.Combine(fooImageRoot, CurrentFooTypes.FooObject.FooImageName));
   return imageURI;
  }
 }

So CurrentFOoTypes and FooObject also supports INotifyPropertyChanged.

So If I bind a TextBlock to CurrentFooTypes.FooObject.FooImageName, if either fooObject or FooImageName change the textblock updates. How can I subscribe my viewmodel object to recieve updates in a similiar fasion.


Correct me if I'm wrong. You want to be notified of changes to the properties FooImageName and FooObject, both owning objects use INotifyPropertyChanged to alert observers that these properties have changed.

Josh Smith had a nice article where he introduced a PropertyObserver object, which is used for just this scenario.

The MVVM Foundation includes this object as well as other helpful objects for MVVM development.

You can use the PropertyObserver, or custom code, to watch for changes in the properties you're interested in (in this case FooObject and FooImageName) and perform whatever actions you need to update the image URI based on those changes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜