DependencyProperties for zenon WPF controls


When you begin to develop WPF controls for zenon, you will soon stumble across DependencyProperties. What are dependency properties? The quick definition from the MSDN documentation says that a dependency property is a "property that is backed by the WPF property system." They are quite similar to normal .NET properties, but the concept behind DependencyProperties is much more

online pharmacy

complex and powerful. It gives you a bunch of infrastructure to do all things you often want to do with a normal property: validate it, coerce it into a proper range, give out change notifications and a number of other aspects. A normal .NET property is read directly from a private member in your class, whereas the value of a DependencyProperty is resolved dynamically when calling the GetValue() method that is inherited from DependencyObject.

Advantages of DependencyProperties:

  • Reduce memory footprint
  • Value inheritance
  • Change notification
  • Value validation

How to create a DependencyProperty:

To create a DependencyProperty, you have simply to add a static field of type DepdencyProperty to your type and call DependencyProperty.Register() to create an instance of a dependency property. The naming convention of DependencyProperties fields is important. The name of the fields is always the name of the property, with the suffix Property appended. To make it accessible like a normal .NET property you need to append a property wrapper. This wrapper does nothing else than internally getting and setting the value by using the GetValue() and SetValue()

usa pharmacy

Methods inherited from DependencyObject and passing the DependencyProperty as key. HINT: If you are using Visual Studio, you can type propdp and hit 2x TAB to create a dependency property.

// Dependency Property
public static readonly DependencyProperty LastNameProperty =
     DependencyProperty.Register( "LastName", typeof(String),
// .NET Property wrapper
public String LastName
    get { return (String)GetValue(LastNameProperty); }
    set { SetValue(LastNameProperty, value); }

Each DependencyProperty provides callbacks for change notification, value coercion and validation. These callbacks are easily registered on the dependency property with

cheap generic cialis


// FrameworkPropertyMetadata
new FrameworkPropertyMetadata( "zenon",

Tags: ,

Leave a Reply