Winphone开发之数据绑定(2)

上一篇文章描述了XAML与CS中类的数据绑定,下面来说一下XAML元素与元素之间的数据绑定。

控件实质上是有两部分的,一部分是UI界面,也就是我们能够看到的界面,另一部分则是界面之后的数据。下面这个例子表明了XAML控件之间的数据交流,主要是下面的一句话:

Text="{Binding ElementName=slide ,Path=Value}"

指明了绑定slide控件的Value属性值。


<phone:PhoneApplicationPage
    x:Class="BindingExample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:src="clr-namespace:BindingExample"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <Grid HorizontalAlignment="Left" Height="768" VerticalAlignment="Top" Width="480">
        <TextBox Name="box" HorizontalAlignment="Left" Height="72" Margin="10,71,0,0" TextWrapping="Wrap" Text="{Binding ElementName=slide ,Path=Value}" VerticalAlignment="Top" Width="456"/>
        <Slider Name="slide" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,318,0,0" Width="417" Maximum="100"  Value="{Binding ElementName=box, Path=Text}"/>
    </Grid>
</phone:PhoneApplicationPage>

上面的TEXTBOX与下面的SLIDE的数值得到了绑定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值