Title: Input And Data Binding in WPF Development
1iFour Consultancy
https//www.ifourtechnolab.com/wpf-software-develo
pment
2Input And Data Binding
- 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-develo
pment
3What We Will Cover
- Binding data to UI Elements
- Using Converters to convert data during Binding
- Using Data Templates to visualize data
https//www.ifourtechnolab.com/wpf-software-develo
pment
4Data Binding Concepts
- Binding Components
- Target Object
- Target Property
- Binding Source
- Path
- Target Property Must be a dependency property
https//www.ifourtechnolab.com/wpf-software-develo
pment
5Binding Modes
- 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-develo
pment
6What Triggers Updates
- 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-develo
pment
7Data Binding Methods
- Binding using XAML
- Binding using Code
ltLabel Name"lblNote" Content"DynamicResource
ResourceKeyNote" /gt ltTextBox Name"txtNote"
VerticalContentAlignment"Top"
HorizontalAlignment"Stretch" Text"Binding
AppointmentNote,ModeTwoWay" VerticalAlignment"S
tretch" Width"Auto" Height"Auto" /gt
MyData myDataObject new MyData(DateTime.Now)
Binding myBinding new
Binding("MyDataProperty") myBinding.Source
myDataObject myText.SetBinding(TextBlock.TextPr
operty, myBinding)
https//www.ifourtechnolab.com/wpf-software-develo
pment
8Converting DataOverview
- Used when data doesnt 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-develo
pment
9Converting Data Out-of-Box Converters
- 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-develo
pment
10Data Templates Overview
- Makes it easy to put content with data
- Easy to define visual styles for data
- Reusable and modifiable
https//www.ifourtechnolab.com/wpf-software-develo
pment