Windows 8 Store Apps学习(52) 绑定2013-12-10 cnblogs webabcd绑定: 与 Element Model Indexer Style RelativeSource 绑定, 以及绑定中的数据转换介绍重新想象 Windows 8 Store Apps 之 绑定与 Element 绑定与 Model 绑定与 Indexer 绑定对 Style 中的 Setter 进行绑定(绑定静态资源)Binding 的一个扩展标记 RelativeSource 的应用绑定中的数据转换示例1、演示如何与 Element 绑定,以及 OneTime, OneWay, TwoWay 的区别Binding/BindingElement.xaml
<Pagex:Class="XamlDemo.Binding.BindingElement"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"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="120 0 0 0"> <!--本例用于演示如何与 Element 绑定,以及 OneTime, OneWay, TwoWay 的区别--><!--OneTime 方式绑定元素--><Slider Name="sliderOneTime" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" /><TextBox Text="{Binding ElementName=sliderOneTime, Path=Value, Mode=OneTime}" Width="150" HorizontalAlignment="Left" /><!--OneWay 方式绑定元素(OneWay 是默认方式)--><Slider Name="sliderOneWay" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" Margin="0 50 0 0" /><TextBox Text="{Binding ElementName=sliderOneWay, Path=Value, Mode=OneWay}" Width="150" HorizontalAlignment="Left" /><!--TwoWay 方式绑定元素--><Slider Name="sliderTwoWay" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" Margin="0 50 0 0" /><TextBox Text="{Binding ElementName=sliderTwoWay, Path=Value, Mode=TwoWay}" Width="150" HorizontalAlignment="Left" /></StackPanel></Grid></Page>
2、演示如何与 Model 进行双向绑定Binding/BindingModel.xaml
<Pagex:Class="XamlDemo.Binding.BindingModel"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"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="120 0 0 0" Name="root"><TextBlock Name="lblMsg" FontSize="14.667" /><TextBox FontSize="14.667" Text="{Binding Path=Name, Mode=TwoWay}" Margin="0 10 10 0" /><TextBox FontSize="14.667" Text="{Binding Age, Mode=TwoWay}" Margin="0 10 10 0" /><ToggleSwitch OffContent="女" OnContent="男" Header="性别" Margin="0 10 10 0"><ToggleSwitch.IsOn><Binding Path="IsMale" Mode="TwoWay" /></ToggleSwitch.IsOn></ToggleSwitch></StackPanel></Grid></Page>