WPF InotifyPropertyChanged and Model View

So, I think I am doing something pretty simple. I know why this doesn't work, but it looks like there should be a direct way to get it to work.

the code:

private string fooImageRoot;
 // ....
 public BitmapImage FooImage
 {
  get
  {
   URI imageURI = new URI(Path.Combine(fooImageRoot, CurrentFooTypes.FooObject.FooImageName));
   return imageURI;
  }
 }

      

So CurrentFOoTypes and FooObject also support INotifyPropertyChanged.

So if I bind the TextBlock to CurrentFooTypes.FooObject.FooImageName, if fooObject or FooImageName changes the textblock updates. How can I subscribe to my viewmodel to receive updates in a fasion like.

+2


a source to share


1 answer


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

Josh Smith had a good article where he introduced the PropertyObserver object that is only used for this scenario.



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

You can use PropertyObserver or custom code to watch for changes to the properties you are interested in (in this case, FooObject and FooImageName) and take whatever action is necessary to update the image URI based on those changes.

+1


a source







All Articles