zoukankan      html  css  js  c++  java
  • WPF之Binding基础一 UI Binding Source

    XMAL代码
    <StackPanel Margin="5" Background="LightBlue">
    <TextBox Margin="5" Height="50" x:Name="txtone"/>
    <Button Margin="5" Height="40" Content="累计" Click="btn_Click"/>
    </StackPanel>
    User类
    //继承通知事件这个接口
    class User:INotifyPropertyChanged
    {
    //声明一个属性改变事件
    public event PropertyChangedEventHandler PropertyChanged;
    private double chengji;
    public double ChengJi
    {
    get { return chengji; }
    set
    {
    chengji = value;
    if (PropertyChanged != null)
    {
    this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("ChengJi"));
    }
    }
    }
    }
    CS代码
    public partial class MainWindow : Window
    {
    User u = new User();
    public MainWindow()
    {
    InitializeComponent();
    //----------------------------------写法1-------------------------------------------
    //Binding binding = new Binding();
    //数据源是User类
    //binding.Source = u;
    //路径是Chengji这个属性
    //binding.Path=new PropertyPath("ChengJi");
    //进行绑定,第一个参数是绑定的目标,就是你要往哪绑定,第二个参数三你要往目标的哪个属性上绑,第三个参数就就是说你要与哪个实例关联
    //BindingOperations.SetBinding(this.txtone, TextBox.TextProperty, binding);

    //----------------------------------写法2-------------------------------------------
    this.txtone.SetBinding(TextBox.TextProperty, new Binding("ChengJi") { Source = u });
    }

    private void btn_Click(object sender, RoutedEventArgs e)
    {
    u.ChengJi += 1;
    }
    }

  • 相关阅读:
    到底该不该熟悉掌握struts2的ONGL呢?
    struts2 request内幕 为什么在struts2用EL表达式可以取值
    struts2 权限拦截器 拦截没有登陆的请求
    tomcat context 配置 项目部署
    tomcat 设置默认编码格式
    工作记录1
    javascript 的学习笔记(第一天)
    JavaScript for...in 循环
    indexof方法区分大小写
    java 和 IntelliJ IDEA 的一些配置
  • 原文地址:https://www.cnblogs.com/lijin/p/WPF.html
Copyright © 2011-2022 走看看