大佬教程收集整理的这篇文章主要介绍了Silverlight 之数据绑定(简单例子),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
首先我们先明确Databinding Mode的3种模式:
OneTime | 目标控件的属性只更新一次,以后的更新会被忽略 |
OneWay | 数据对象的值会同步到目标控件的属性,但是目标控件的属性改变不会被同步到数据对象中 |
TwoWay | 目标控件的属性和数据对象的值相互同步 |
其中,用于OneWay和TwoWay绑定的对象都必须实现“INotifyPropertyChanged”接口
实现范例:
public class TESTClass : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; privatE int _id; public int id { get { return _id; } set { _id = value; _name = "Name" + value; if (PropertyChanged != null) { PropertyChanged.Invoke(this,new PropertyChangedEventArgs("Name")); } } } private String _name="Text Box"; public String Name { get { return _name; } set { _name = value; } } }
首先需要引入绑定对象的命名空间:
xmlns:local="clr-namespace:TestPhoneApp"
<phone:PhoneApplicationPage.resources> <local:TESTClass x:Key="TESTClass"/> </phone:PhoneApplicationPage.resources>
<TextBox Height="72" HorizontalAlignment="Left" Margin="0,186,0" Name="textBox2" Text="{Binding Path=Id,Mode=OneTime,source={Staticresource TESTClass}}" VerticalAlignment="Top" Width="460" /> <TextBox Height="72" HorizontalAlignment="Left" Margin="0,287,0" Name="textBox3" Text="{Binding Path=Name,Mode=OneWay,source={Staticresource TESTClass}}" VerticalAlignment="Top" Width="460" />
以上是大佬教程为你收集整理的Silverlight 之数据绑定(简单例子)全部内容,希望文章能够帮你解决Silverlight 之数据绑定(简单例子)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。