locked
DependencyProperty Object RRS feed

  • Question

  • Hi,

    I didn't get why is there use of dependency property object. Why can't we directly access some property of object ?

    can any one please explain this.

    Thanx in advance

    Monday, May 25, 2009 3:21 AM

Answers

  • A dependency property object does some other things for you behind the scenes like firing notifications when values change. Another interesting ability is that you can give your children dependency properties, like in the case of a Grid. A Grid gives its children Row, Column, RowSpan, and ColumnSpan properties.

     This page is pretty useful when creating dependency properties:

    http://www.kirupa.com/blend_silverlight/dependency_property_generator.htm

     

    Monday, May 25, 2009 8:33 AM

All replies

  •  DependencyProperties are used to bind into using data binding features. For example this dependency property:

     

    public static readonly DependencyProperty IsSpinningProperty = 
    DependencyProperty.Register(
    "IsSpinning", typeof(Boolean),
    typeof(Page4), null
    );
    public bool IsSpinning
    {
    get { return (bool)GetValue(IsSpinningProperty); }
    set { SetValue(IsSpinningProperty, value); }
    }
    You could bind this property when you instance your user control:
    <MyProject:MyControl IsSpinning="{Binding Property1}" />
     Where Property1 is a public property of the Data Context :-) 

    This example was taken from: http://msdn.microsoft.com/en-us/library/cc221408(VS.95).aspx 

     Cheers!

    Monday, May 25, 2009 4:34 AM
  • A dependency property object does some other things for you behind the scenes like firing notifications when values change. Another interesting ability is that you can give your children dependency properties, like in the case of a Grid. A Grid gives its children Row, Column, RowSpan, and ColumnSpan properties.

     This page is pretty useful when creating dependency properties:

    http://www.kirupa.com/blend_silverlight/dependency_property_generator.htm

     

    Monday, May 25, 2009 8:33 AM
  • Greets,

    While you can use regular CLR properties on an object and still be able to use binding, you get added benefits from dependency properties such as being able to create styles that can be applied to your objects, have your properties participate in animation (for example, a person could use expression blend to change the value of your property over a timeline) and get callback notifications when your dependency property has changed.

    Attached properties, a special type of dependency property, are very useful to store meta-data for dependency objects making it 'seem' like they implement the property.  As an example, I use attached dependency properties to store extra information about controls on a form without actually deriving from those controls and adding new properties.

    Regards,

     Joe

    Thursday, May 28, 2009 8:56 PM