打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WPF 绑定到非FrameworkElement对象

WPF 绑定到非FrameworkElement对象

(2013-01-31 09:19:47)
         <Label>请输入姓名:</Label>
          <TextBoxBackground="SkyBlue">
            <!--使用属性元素语法绑定到Person类,指定Path为PersonName公共属性-->
            <TextBox.Text>
                <Binding Source="{StaticResource myDataSource}"Path="PersonName" Mode="TwoWay"UpdateSourceTrigger="PropertyChanged"/>
            </TextBox.Text>
         </TextBox>
          <StackPanelOrientation="Horizontal">
         <Label>输入的名字:</Label>
         <!--使用Source属性获取更新后的属性值,由于Person类实现了INotifyPropertyChanged接口,因此更改会立即被显示-->
             <TextBlock Background="Orange"Text="{Binding Source={StaticResource myDataSource},Path=PersonName}" Width="100" Height="30"HorizontalAlignment="Left"/>
         </StackPanel>



   //实现INotifyPropertyChanged
    //以支持单向和双向绑定
    public class Person :INotifyPropertyChanged
    {
       private string _personName;
       public string PersonName
       {
          get 
          
              return_personName; 
           }
           set
           {
              _personName = value;
             OnPropertyChanged("PersonName");
           }
       }
       
       public Person()
       {
       }
       public Person(string value)
       {
          this._personName = value;
       }

       public event PropertyChangedEventHandlerPropertyChanged;
       protected void OnPropertyChanged(stringpropertyName)
       {
          PropertyChangedEventHandler handler = PropertyChanged;
           if(handler != null)
           {
              handler(this, newPropertyChangedEventArgs(propertyName));
           }
       }
    }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Silverlight 4 数据绑定
闲话WPF之二一(WPF中的数据处理 [3])
Data Binding和INotifyPropertyChanged是如何协调工作的?
关于WPF的验证
深入浅出WPF之Binding的使用(一)
asp.net2.0 hiddenfield控件_asp.net技巧-NET编程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服