WPF Binding表达式
前言:
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表达式的更多相关文章
- WPF binding 参考
Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silve ...
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...
- WPF Binding值转换器ValueConverter使用简介(二)-IMultiValueConverter
注: 需要继承IMultiValueConverter接口,接口使用和IValueConverter逻辑相同. 一.MultiBinding+Converter 多值绑定及多值转换实例 当纵向流量大于 ...
- WPF Binding值转换器ValueConverter使用简介(一)
WPF.Silverlight及Windows Phone程序开发中往往需要将绑定的数据进行特定转换,比如DateTime类型的时间转换为yyyyMMdd的日期,再如有一个值是根据另外多组值的不同而异 ...
- WPF Binding
winform有binding, WPF也有binding,区别在哪呢?这里暂时不提.以前也检查接触WPF binding, 但为什么过段时间就忘记了呢? 可能主要原因自己的知识体系不够完善吧,下面我 ...
- WPF Binding Mode,UpdateSourceTrigger
WPF 绑定模式(mode) 枚举值有5个1:OneWay(源变就更新目标属性)2:TwoWay(源变就更新目标并且目标变就更新源)3:OneTime(只根据源来设置目标,以后都不会变)4:OneWa ...
- WPF Binding ElementName方式无效的解决方法--x:Reference绑定
原文:WPF Binding ElementName方式无效的解决方法--x:Reference绑定 需求: 背景:Grid的有一个TextBlock name:T1和一个ListBox,ListBo ...
- WPF 杂谈——Binding表达式
不管是定义控件还是用户控件都会用到一个功能--绑定(Binding).书面的叫法:元素绑定.意思就是让绑定的元素实现数据同步.在笔者看来WPF引入这一个功能实在是太完美了.编程更加的具体化.特别是跟M ...
- UpdateSourceTrigger Property in WPF Binding
介绍 这篇文章我将介绍在WPF和Silverlight中更新绑定源的概念.正如您所知道的,当我们用TwoWay的模式绑定时,任何在目标控件上发生的变化都会影响绑定源的值. 请注意只是在用TwoWay绑 ...
- .NET: WPF Binding对数据的校验和转换以及多路Binding
一.校验 一般需要对target上的值进行校验. xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns=" ...
随机推荐
- (0321) 路科 视频 ,讲 uvm_pkg
loading
- h5 json 生成excel
引入库文件 创建下载按钮 Download Demo Excel 实现转换 var data = [ ["Joa Doe", "joa@doe.com"], [ ...
- 夸克开发板 FaceDetectOnTft.py 测试
① 连接usb 摄像头,执行 dmesg | grep -i video 查看设备识别情况 同时可看到 frame buffer 显示设备(自带的 tft LCD)名称 ② 摄像头识别的设备名为, / ...
- 调度器44—root_domain—更新路径
1. root_domain 的路径的赋值路径 kernel_init_freeable //内核初始化路径调用 [2] sched_init_smp //core.c 传参 cpu_active_ ...
- ider git Reset Type 使用记录
Soft:在选定提交点之后所做的所有更改都将被暂存(这意味着可以到 Version Control 窗口(Alt+9)的Local Changes 选项卡,以便您可以查看它们,并在必要时稍后提交). ...
- VsCode——修改左侧目录缩进
https://code84.com/741691.html https://blog.csdn.net/qq812457115/article/details/124445657
- 第15周作业--JDBC连接数据库
编写一个应用程序,输入用户名和密码,访问test数据库中t_login表(字段包括id.username.password),验证登录是否成功.当登录成功后,将t_user表(id.name.sex. ...
- C盘满了
今天电脑提示说C盘磁盘满了,于是开始做磁盘清理 右击C盘,点管理. 点击磁盘清理,勾选中临时文件.下载.回收站.缩略图,然后点击清理系统文件. 再去查看C盘仍然没有多大变化,于是挨个翻看C盘到底哪 ...
- c#怎样删除指定文件名的文件
我有一个文件夹,里面有6个文件,我现在要删除字母B开头的三个文件,只需要剩下A开头的文件即可用C#怎样操作??? foreach (string d in Directory.GetFileSyste ...
- Google在线深度学习神器Colab——科研角色
转载:Google在线深度学习神器Colab - 简书 (jianshu.com) 转载:不FQ,免费使用带GPU和TPU的深度学习开发环境_colab (sohu.com)