Académique Documents
Professionnel Documents
Culture Documents
http://www.LearnNowOnline.com
Objectives
Learn to use Binding objects to bind data sources and targets Add data converters to manage conversion during the binding process Use data templates to modify the layout of bound data in lists
Agenda
Introducing Binding Working with Type Converters Binding Lists and Data Templates Using Binding and Data Templates
DependencyObject instance
in code
Can set Mode property of Binding to control direction of data flow (one/two directions?)
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Value Converters
Value Converter provides instance of class that implements Windows.UI.Xaml.Data.IValueConverter interface Binding declaratively often requires value converter
Value Converters
Select a customer from a ListBox, display combined FirstName and LastName fields in TextBlock Select an integer, bind to BorderThickness of Border
Cant bind directlyBorderThickness is a Thickness
structure
Binding Details
Standard Binding markup extension includes ElementName and Path attributes:
Text="{Binding ElementName=DemoSlider,
Path=Value}"
ElementName=DemoSlider}"
Binding Details
Path property can refer to property, or property of a property, or indexed property Need to refer to an attached property?
Grid.Row, for example
Set Path property to (Grid.Row) (in parentheses) Parentheses force evaluationwont work without Parentheses not necessary for property of a property
Binding Details
Binding Markup extension shortcut for child element syntax:
<TextBox Width="40" Name="DemoTextBox" Height="23"> <TextBox.Text> <Binding ElementName="DemoSlider" Path="Value" /> </TextBox.Tet> </TextBox>
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Binding is one-way: Data moves in one direction Set Mode property of Binding to change
OneTime OneWay
TwoWay
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
DEMO
Two-way binding, SimpleBinding3
A Simple Example
Enter text into TextBox, update TextBlock with length of the text Could react to TextChanged event of TextBox Better: Bind Text property of TextBlock to Text.Length property of TextBox
Points out that binding can use expressions
DEMO
SimpleBinding4
Agenda
Introducing Binding Working with Type Converters Binding Lists and Data Templates Using Binding and Data Templates
binding)
values
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Converters
Implement IValueConverter interface Requires Convert and ConvertBack methods Parameters:
value (System.Object)
targetType (System.Type)
parameter (System.Object) Language (System.String)
Converter Warning
Converter doesnt trap exceptions
Treated as runtime errors
DEMO
IntegerToThicknessConverter
x:Key="thicknessConverter" />
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
End of Part 1
http://www.LearnNowOnline.com