views:

46

answers:

3

I'm trying to bind some WPF controls to a sealed class provided to me. Because it is sealed, I cannot inherit from it to create a class that implements INotifyPropertyChanged. So I'm not sure how I should go about doing this. Should I create a wrapper that implements INotifyPropertyChanged? Anyone have any tips on what to do?

+4  A: 

Wrapping the class in a view model that provides notification (and maybe validation, editing support etc.) is the usual approach. The question is whether the underlying object is modified elsewhere in your process and, if so, whether you want those changes to be automatically reflected in the UI. If you do, you'll need a more centralized approach - usually by way of a service that manages those objects.

HTH,
Kent

Kent Boogaart
Thanks! I won't be modifying the underlying object anywhere else in the code, so it sounds like the view model wrapper would be the right choice. Thanks!
NickAldwin
+1  A: 

Hmm, I would put a wrapper around it. It's like the approach in MVVM. The Model is wrapped by the ViewModel.

DHN
+1  A: 

If the binding is for reading only you can get away with not implementing INotifyPropertyChanged and just having the binding.

Ciemnl