locked
XAML and binding to properties in a base class RRS feed

  • Question

  • If I have a class Device that implements INotifyPropertyChanged and exposes a property Size and I bind a XAML control to that - perhaps a TextBlock. Then any time the Device alters the Size the displayed TextBlock will change (assume it does and its all working fine).

    Well what if I create a SuperDevice which inherits Device - but SuperDevice neither implements INotifyPropertyChanged nor itself has a property named Size, then will the binding work if the data source becomes a SuperDevice rather than a Device?

    In other words does binding recognize INotifyPropertyChanged when its only implemented in a base class of an object being bound to?

    Cap'n


    Tuesday, November 5, 2013 9:05 PM

Answers

  • Your derived object will export the public methods and properties that it defines as those from the base class. This is the point behind inheritance. Please see the Inheritance docs for more information.

    --Rob

    • Marked as answer by Anne Jing Thursday, November 14, 2013 9:18 AM
    Tuesday, November 5, 2013 9:30 PM
    Moderator

All replies

  • It's all the same from outside of the derived object. The binding engine cares only about what the object exports, not about the object's internal implementation.

    --Rob

    Tuesday, November 5, 2013 9:10 PM
    Moderator
  • It's all the same from outside of the derived object. The binding engine cares only about what the object exports, not about the object's internal implementation.

    --Rob

    The derived class does not implement INotifyPropertyChanged and does not have a property named Size - only the base class has these and it defines Size as a public property (not protected).

    Will this all work fine?

    Cap'n


    Tuesday, November 5, 2013 9:14 PM
  • Scratch that Rob - my apologies - the derived class DOES have that interface and implements it badly, this was causing confusion and led to my question - it all makes sense actually !

    Thx

    Tuesday, November 5, 2013 9:28 PM
  • Your derived object will export the public methods and properties that it defines as those from the base class. This is the point behind inheritance. Please see the Inheritance docs for more information.

    --Rob

    • Marked as answer by Anne Jing Thursday, November 14, 2013 9:18 AM
    Tuesday, November 5, 2013 9:30 PM
    Moderator