前言:
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. Python170道面试题

    1. 谈谈对 Python 和其他语言的区别 答:Python 是一门语法简洁优美,功能强大无比,应用领域非常广泛,具有强大完备的第三方库,他是一门强类型的可移植.可扩展,可嵌入的解释型编程语言,属于 ...

  2. pyg安装

    pyg官网:pytorch_geometric documentation (pytorch-geometric.readthedocs.io) win安装pyg各种报错,原因在于pytorch和py ...

  3. OCR接口

    OCR基础框 import pytesseract from PIL import Image img = Image.open('实际数据1.jpeg') #具体位置截图 image1 = Imag ...

  4. 力扣51. N 皇后(回溯法)

    按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子. n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. 给你一个整数 n ,返回 ...

  5. thirty-two(模型点击展示)react-three-fiber

    模型点击蒙版展示 点击展示目的(用户需要看见模型中更加多的内容信息) 使用技术 ThreeJs.React-three-fiber.React-three-drei.React.css 整体思路:   ...

  6. AngularJS UI

    1, angular ui 自定义弹框 <script type="text/ng-template" id="stackedModal.html"> ...

  7. hdrp package导入工程

    补充: 可以直接把包提出来放一个单独文件夹 然后在package manager中load from disk,跟下面手动改效果没区别 如果发现有各种引用丢失,在工程内对包reimport下 1 需要 ...

  8. fastadmin添加自定义按钮

    问题:关于fastadmin框架列表页面自定义按钮功能 案例:自定义一个同步数据的按钮 <a href="javascript:;" class="btn btn- ...

  9. 学生网络创业交流会-2021年office

    1.课程的讲解之前,先来对题目进行分析,首先需要在考生文件夹下,将Wrod素材.docx文件另存为Word.docx,后续操作均基于此文件,否则不得分. 2.这一步非常的简单,打开下载素材文件,在[文 ...

  10. ABAP 范围表 range table

    范围表定义: DATA gr_test TYPE RANGE OF char6. 做选择屏幕的时候 范围选择框 默认就是一个范围表 范围表内容: 通过断点调试可以看到,范围表有4列 sign opti ...