Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

DependencyObject

System.Object
    System.Windows.Threading.DispatcherObject
        System.Windows.DependencyObject

Classes derive from DependencyObject to employ WPF's dependency property (DP) system. The majority of WPF element types implement their properties using the GetValue and SetValue helper functions provided by DependencyObject. Chapter 18 illustrates this technique.

By handing control of a property to the dependency property system, we can take advantage of data binding, styling, animation, property value inheritance, default values, per-type metadata, and property change notifications.

It is fairly unusual to derive directly from DependencyObject—your classes will normally derive from one of the other classes described in this appendix, inheriting from DependencyObject indirectly. However, one scenario where deriving directly from this class can be useful is if you are writing a class whose only job is to act as a data binding source, with values that change on a regular basis. Although WPF supports ordinary CLR properties and can use the .NET Framework class library's INotifyPropertyChange interface to discover when properties change, it needs to use reflection to read ordinary properties. However, when binding to a dependency property, WPF provides the property implementation, so it does not need to use reflection to read properties, nor does it need to rely on property change events. This makes binding to a dependency property slightly more efficient than binding to an ordinary ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page