[progress Communities] [progress Openedge Abl] Forum Post: Need To Known What Are The Types...

Status
Not open for further replies.
N

nicolewells.n

Guest
DataBinding is a mechanism in WPF applications that provides a simple and easy way for applications to display and interact with the data. It allows the flow of data between UI and business model. Any modification done on data in your business model after binding is done, will automatically reflect to the UI, and vice versa. Binding can be one directional or bidirectional. The source of databinding can be a normal .NET property or Dependency property, however the target property must be a Dependency property. For making binding work properly, both sides of the property must provide change in notification which will tell the binding to update the target value. In normal .NET properties, it can be achieved by using INotifyPorpertyChanged interface. And for Dependency properties, it is done by PropertyChanged callback of property metadata. Databinding is achieved in XAML by using Binding mark-up extension i.e. {Binding}. DataContext Datacontext property is used for setting the data to UI. If you do not explicitly define source of binding, then it takes data context as default. Types of Binding OneWay TwoWay OneWayToSource OneTime One Way In this type of binding, data is bound to its source i.e. business model to its target i.e. UI. In xaml file _Name: _Age: Now, in xaml.cs file, using System.Windows; namespace WPF DataBinding { public partial class MainWindow: Window { Person person = new Person { Name = "Salman", Age = 26 }; public MainWindow() { InitializeComponent(); this.DataContext = person; } private void Button_Click(object sender, RoutedEventArgs e) { string message = person.Name + " is " + person.Age; MessageBox.Show(message); } } public class Person { private string nameValue; public string Name { get { return nameValue; } set { nameValue = value; } } private double ageValue; public double Age { get { return ageValue; } set { if (value != ageValue) { ageValue = value; } } } } } Two Way In WPF, data is getting updated from both sides i.e. source and target. If there is any change from UI, it updates the business model, and vice versa. _Name: _Age: OneWayToSource OneWayToSource is the reverse of OneWay binding; it updates the source property when the target property changes. OneTime This has the same behaviour as OneWay except it will only update the user interface one time. This should be your default choice for binding.

Continue reading...
 
Status
Not open for further replies.
Top