Logo
programming4us
programming4us
programming4us
programming4us
Windows XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
 
Windows Phone

Data Bindings : Notification Mechanisms

3/22/2011 4:28:14 PM
For data bindings to work, the binding source must implement some kind of notification mechanism. This notification mechanism signals when the property value has changed so the new value can be retrieved from the source and transferred to the target. When you bind the Value property of a Slider to the Text property of a TextBlock, you’re dealing with two dependency properties. Although you can’t see it in the public programming interfaces, dependency properties provide this notification mechanism.

Connecting two visual elements with a data binding is certainly convenient, but the most powerful data bindings involve a target that is a visual element but a source that is not, and which instead is probably something commonly referred to as a business object.

And now a warning is required:

Sometimes when programmers learn a new and important feature of an operating system —they feel a need to use that feature everywhere, perhaps just to try it out and give it some exercise. With dependency properties, this is not such a good idea. Certainly you should use dependency properties when you’re deriving from classes that already derive from DependencyObject, but you probably shouldn’t derive from DependencyObject for the sole purpose of using dependency properties.

In other words: Don’t start rewriting your business objects to use dependency properties!

Targets of data bindings must be dependency properties, but that is not a requirement for binding sources. Binding sources can be just regular old properties on regular old classes. However, if the source is changing, and you want the target updated with the current value of the source, the source must implement some kind of notification mechanism.

Almost always, business objects that serve as binding sources should implement the notification mechanism known as the INotifyPropertyChanged interface.

INotifyPropertyChanged is defined in the System.ComponentModel namespace—a clear indication that it transcends Silverlight and plays a very important role in .NET. This is how business objects provide notification that data has changed in some way.

INotifyPropertyChanged is also extremely simple, being defined like this:

public interface INotifyPropertyChanged
{
event PropertyChangedEventHandler PropertyChanged:
}

A class can implement INotifyPropertyChanged simply by having a public event named PropertyChanged. In theory, the class needn’t actually do anything with this event, but proper decorum mandates that the class fires this event whenever one of its properties changes.

The PropertyChangedEventHandler delegate is associated with a PropertyChangedEventArgs class that has a single public get-only property named PropertyNamePropertyChangedEventArgs constructor. of type string. You pass the name of the property that’s changed to the

Sometimes a class that implements INotifyPropertyChanged will have a protected virtual method named OnPropertyChanged with an argument of type PropertyChangedEventArgs. This isn’t required but it’s convenient for derivative classes. I do this in my examples because the method is a convenient place to fire the event.

Because business objects that implement INotifyPropertyChanged do not derive from FrameworkElement, they do not form part of the visual tree in a XAML file; usually they’ll be instantiated as XAML resources or in the code-behind file.

Other -----------------
- Data Bindings - The “this” Source
- Data Bindings - Relative Source
- Data Bindings - Binding Converters
- Data Bindings : Target and Mode
- Data Bindings : Source and Target
- Dependency Properties - Attached Properties
- Dependency Properties - Panels with Properties
- Dependency Properties - A New Type of Toggle
- Dependency Properties - Deriving from UserControl
- Dependency Properties - The Dependency Property Difference
 
 
Trailer game
Video tutorials
- How To Install Windows 8 On VMware Workstation 9

- How To Install Windows 8

- How To Install Windows Server 2012

- How To Disable Windows 8 Metro UI

- How To Change Account Picture In Windows 8

- How To Unlock Administrator Account in Windows 8

- How To Restart, Log Off And Shutdown Windows 8

- How To Login To Skype Using A Microsoft Account

- How To Enable Aero Glass Effect In Windows 8

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
programming4us programming4us
Trailer game
 
programming4us
Girls
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone