Dependency Property

advertisement
Dependency Property
Mahender
Senior Software Engineer
United Health Group
Mahender Sarangam
• Having 5 years of experience on .NET Technologies.
Working as a Senior Software Engineer in United
Health Group(UHG India Information Service
Ltd.). Worked with Big Firms like Deloitte
Consulting & Wipro Technology.
• Got Technical Acquaintance on Technologies like
C#, ASP.NET,AJAX, LINQ, Silverlight, WPF,WCF ,SQL
Server, Team Foundation Server(TFS) and SharePoint
Technology.
• MCTS Certified in Web Technologies.
Dependency Property
• A Dependency Property is a static method that
changes the value of a instanced object 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); }
}
• A property of an element that depends on a
number of property-providers outside the element
is called a "dependency property"
• Any class inherits from
System.Windows.DependencyObject can be extended
with dependency properties.
• Support higher level features such as property value
change notification, property validation, property
coercion, property metadata and default property value
inheritance.
• Dependency Property is like any other property but can
hold a default value, with built in mechanism for property
value validation and automatic notification for changes in
property value ( for anyone listening to property value especially UI) and any binding in Silverlight is to binded
to a Dependency Property
Microsoft Definition of DP
• The purpose of dependency properties is to provide a
way to compute the value of a property based on the
value of other inputs. These other inputs might include
external properties such as user preference, just-intime property determination mechanisms such as data
binding and animations/storyboards, multiple-use
templates such as resources and styles, or values
known through parent-child relationships with other
elements in the object tree. In addition, a dependency
property can be implemented to provide callbacks
that can propagate changes to other properties.
• A property changed callback method is invoked ,the
property changed callback should also be a
static/Shared method/function, which take two
parameters – DependencyObject and
DependencyPropertyChangedEventArgs.
• The DependencyPropertyChangedEventArgs, holds
three properties
– NewValue
– OldValue
– Property
When to choose Dependency
property
• We should implement your property as a dependency property
whenever you want the property to support one or more of the
following Silverlight property system capabilities:
• You want the property to be settable in a style.
• You want the property to be a property target that supports data
binding. For more information about data binding dependency
properties.
• You want the property to support an animated value, using the
Silverlight animation system.
• You want the Silverlight property system to report when the
previous value of the property has been changed by actions taken
by the property system itself, the environment, or the user, or by
reading and using styles. Your property can specify a callback
method that will be invoked each time the property system
determines that your property value was definitively changed
Demo
Thank you
Download