Binding: Binding with Element Model Indexer Style RelativeSource, and data conversion in bindings
Introduced
Re-imagine the bindings of Windows 8 Store Apps
Binding with Element
With Model binding
Binding with Indexer
Bind a Setter in a Style (bind a static Resource)
Application of an extended tag RelativeSource for Binding
Data transformations in Bindings
Example
1, demonstrates how to bind with the Element, and onetime, oneway, TwoWay difference
Binding/bindingelement.xaml
<page x:class= "XamlDemo.Binding.BindingElement" xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentat Ion "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using:XamlDemo.Binding "xmlns:d=" http ://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/ markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0 0 0" > <!--This example demonstrates how to bind to the Element, as well as onetime, OneWay, TwoWay
The difference between--> <!--onetime way binding elements-->
<slider name= "Slideronetime" minimum= "1" maximum= "ten" value= "" width= "180" horizontalalignment= "left"/> <textbox text= "{Binding elementname=slideronetime, path=value, mode=onetime}" width= "" horizontalalignment= "Le FT "/> <!--ONeway binding elements (OneWay is the default)--> <slider name= "Slideroneway" minimum= "1" maximum= "value=" "Width=" 180 "horizontalalignment=" left "margin=" 0 0 0 "/> <textbox text=" {Binding elementname=slid
Eroneway, Path=value, Mode=oneway} "width=" horizontalalignment= "left"/> <!-- TwoWay method Binding element--> <slider name= "Slidertwoway" minimum= "1" maximum= "value=" "width=" 18 0 "horizontalalignment=" left "margin=" 0 0 0 "/> <textbox text=" {Binding elementname=slidertwoway, Pat H=value, Mode=twoway} "width=" horizontalalignment= "left"/> </StackPanel> </Grid> ;/page>
2, how to demonstrate with the Model for two-way binding
Binding/bindingmodel.xaml
<page x:class= "XamlDemo.Binding.BindingModel" xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentatio N "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using:XamlDemo.Binding "xmlns:d=" http:/ /schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/ 2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin=" 0 0 0 "Na
Me= "root" > <textblock name= "lblmsg" fontsize= "14.667"/> <textbox fontsize= "14.667" text= "{Binding path=name, mode=twoway}" margin= "0 0"/> <textbox F Ontsize= "14.667" text= "{Binding age, Mode=twoway}" margin= "0 ten 0"/> <toggleswitch offcontent= "female" on content= "Male" header= "gender" margin= "0 0" > <ToggleSwitch.IsOn> <binding P Ath= "Ismale" mode= "TwoWay"/>
</ToggleSwitch.IsOn> </ToggleSwitch> </StackPanel> </Grid> </Page>