前言:
WPF BindingBinding表达式的使用,可以很方便的绑定参数和更新界面数据。

1.界面添加控件,并设置对应属性的Binding表达式,例如:

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel>
<TextBlock FontSize="18">请扫码:</TextBlock>
<TextBox MinWidth="200" Height="252" Margin="2" Text ="{Binding BarID}"></TextBox>
</StackPanel>
</Grid>
</Window>

2.编写Binding类,例如:

        public class MainUI : INotifyPropertyChanged
{
private string _BarID; public string BarID
{
get { return _BarID; }
set
{
_BarID = value;
if (PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("BarID"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}

3.当前界面赋值给这个Binding类:

3.1实例化Binding类:

        MainUI mainUI = new MainUI();

3.2,界面赋值:

            this.DataContext = mainUI;

3.3 调用:

            mainUI.BarID = "123";

此时界面上的TextBox 同样显示“123”。

WPF Binding表达式的更多相关文章

  1. WPF binding 参考

    Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silve ...

  2. WPF入门教程系列(二) 深入剖析WPF Binding的使用方法

    WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...

  3. WPF Binding值转换器ValueConverter使用简介(二)-IMultiValueConverter

    注: 需要继承IMultiValueConverter接口,接口使用和IValueConverter逻辑相同. 一.MultiBinding+Converter 多值绑定及多值转换实例 当纵向流量大于 ...

  4. WPF Binding值转换器ValueConverter使用简介(一)

    WPF.Silverlight及Windows Phone程序开发中往往需要将绑定的数据进行特定转换,比如DateTime类型的时间转换为yyyyMMdd的日期,再如有一个值是根据另外多组值的不同而异 ...

  5. WPF Binding

    winform有binding, WPF也有binding,区别在哪呢?这里暂时不提.以前也检查接触WPF binding, 但为什么过段时间就忘记了呢? 可能主要原因自己的知识体系不够完善吧,下面我 ...

  6. WPF Binding Mode,UpdateSourceTrigger

    WPF 绑定模式(mode) 枚举值有5个1:OneWay(源变就更新目标属性)2:TwoWay(源变就更新目标并且目标变就更新源)3:OneTime(只根据源来设置目标,以后都不会变)4:OneWa ...

  7. WPF Binding ElementName方式无效的解决方法--x:Reference绑定

    原文:WPF Binding ElementName方式无效的解决方法--x:Reference绑定 需求: 背景:Grid的有一个TextBlock name:T1和一个ListBox,ListBo ...

  8. WPF 杂谈——Binding表达式

    不管是定义控件还是用户控件都会用到一个功能--绑定(Binding).书面的叫法:元素绑定.意思就是让绑定的元素实现数据同步.在笔者看来WPF引入这一个功能实在是太完美了.编程更加的具体化.特别是跟M ...

  9. UpdateSourceTrigger Property in WPF Binding

    介绍 这篇文章我将介绍在WPF和Silverlight中更新绑定源的概念.正如您所知道的,当我们用TwoWay的模式绑定时,任何在目标控件上发生的变化都会影响绑定源的值. 请注意只是在用TwoWay绑 ...

  10. .NET: WPF Binding对数据的校验和转换以及多路Binding

    一.校验 一般需要对target上的值进行校验. xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns=" ...

随机推荐

  1. 性能测试-IO密集型-直接会话可能会断了,命令执行不了

    1.IO密集型模拟命令 该命令会开启1个worker不停的读写临时文件,同时启动6个workers不停的调用sync系统调用提交缓存 stress-ng -i 6 --hdd 1 --timeout ...

  2. Maven中的元素Exclusions、modules、parent、properties以及import

    Dependencies:是可选依赖(Optional Dependencies) Exclusions:是依赖排除(Dependency Exclusions) 2.Dependencies (1) ...

  3. MySQL半一致读实验

    参考资料: https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html https://www.y ...

  4. js 自定義event

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. MySQL中的索引应用

    1.什么是索引(Index)? 官方的定义是索引是一种数据结构,从生活的纬度上讲,假如将一本书比作成一张表,这本书的目录就是表中的索引(Index). 2.索引的优势和劣势? 优势:数据量比较大时,为 ...

  6. Qt 一键部署脚本

    echo "begin deploying..." echo Setting up environment for Qt usage... set PATH=C:\Qt\Qt5.8 ...

  7. uniapp改变icon

    <!DOCTYPE html><html lang="zh-CN"> <head> <meta charset="utf-8&q ...

  8. Java8函数式编程(A)

    将行为作为数据传递 函数编程的最直接的表现,莫过于将函数作为数据自由传递,结合泛型推导能力,使代码表达能力获得飞一般的提升. Java8怎么支持函数式编程? 主要有三个核心概念: 函数接口(Funct ...

  9. mplfinance常用方法

    一.主题相关 查看可用预设主题 mpf.available_styles() 默认的主题包括:'binance','blueskies','brasil','charles','checkers',' ...

  10. SVD动态图

    library(gganimate) library(gifski) # 构造数据 phi<-pi/6 theta<-pi/3 c<-matrix(c(cos(phi),sin(ph ...