Input And Data Binding in WPF Development

Page 1

Input And Data Binding iFour Consultancy

https://www.ifourtechnolab.com/wpf-software-development


ď ą

Windows Presentation Foundation (WPF) provides a powerful API with the help of which applications can get input from various devices such as mouse, keyboard, and touch panels.

ď ą

Data binding is the process that establishes a connection between the application UI and business logic. If the binding has the correct settings and the data provides the proper notifications, then, when the data changes its value, the elements that are bound to the data reflect changes automatically

https://www.ifourtechnolab.com/wpf-software-development


 

Binding data to UI Elements Using Converters to convert data during Binding Using Data Templates to visualize data

https://www.ifourtechnolab.com/wpf-software-development


Binding Components  Target Object  Target Property  Binding Source  Path Target Property Must be a dependency property

https://www.ifourtechnolab.com/wpf-software-development


 

OneWay-Updates the target property only when the source property change. TwoWay-Updates the target property or the property whenever either the target property or the source property changes. OneWayToSource-updates the source property when the target property changes OneTime- Updates the target property only when the application starts or when the DataContext undergoes a change.

https://www.ifourtechnolab.com/wpf-software-development


 

Triggering supported by TwoWay or OneWayToSource mode of binding Dependency property or INotifyPropertyChanged UpdateSourceTrigger property  Explicit -Updates the binding source only when you call.  UpdateSource- method.  LostFocus-Updates the binding source whenever the binding target element loses

https://www.ifourtechnolab.com/wpf-software-development


Binding using XAML Binding using Code

<Label Name="lblNote" Content="{DynamicResource ResourceKey=Note}" /> <TextBox Name="txtNote" VerticalContentAlignment="Top" HorizontalAlignment="Stretch" Text="{Binding AppointmentNote,Mode=TwoWay}" VerticalAlignment="Stretch" Width="Auto" Height="Auto" /> MyData myDataObject = new MyData(DateTime.Now); Binding myBinding = new Binding("MyDataProperty"); myBinding.Source = myDataObject; myText.SetBinding(TextBlock.TextProperty, myBinding); https://www.ifourtechnolab.com/wpf-software-development


Used when data doesn’t match between bindings create a conversion class When to use  Culture changes needed  Different View of data then native storage  Incompatible data types between target and source

https://www.ifourtechnolab.com/wpf-software-development


Contained in the System.Windows.Controls namespace BooleanToVisibilityConverter  Converts True/False to Visible, Hidden or Collapsed BorderGapMaskConverter  Represents a converter that converts the dimensions of a GroupBox control into a VisualBrush

https://www.ifourtechnolab.com/wpf-software-development


 

Makes it easy to put content with data Easy to define visual styles for data Reusable and modifiable

https://www.ifourtechnolab.com/wpf-software-development


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.