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=" ...
随机推荐
- Go--求数组奇偶数之和
package main //申明main包 import "fmt" // 导入fmt标准库 func main() { arr := [...]int{01, 11, 22, ...
- (0319) uvmgen的使用,产生的UVM环境介绍
qq https://blog.csdn.net/hh199203/article/details/118210541
- GO 语言中的 sync Map
为什么需要 sync map go 语言之所以引入 sync.Map主要是因为GO 语言自带的 map 是线程不安全的.只能保证并发的读,但是不能保证并发的写. 看下面的例子: func main() ...
- Jenkins+Docker 实现一键自动化部署项目!
博主分享的非常好:https://mp.weixin.qq.com/s/a0JOuiqLsUMcQSEjZ4uGTg 本文章实现最简单全面的Jenkins+docker+springboot 一键自动 ...
- 日常开发记录-this.$message,this.$prompt,交换弹窗确定和取消按钮的位置,确定在左,取消在右
代码: <template> <el-button type="text" @click="open">点击打开 Message Box ...
- 双CAN通讯模板
本文中CAN1采用16位掩码,CAN2只能使用大于等于14的筛选器组,根据手册只能使用32位的掩码(因为大于14的筛选器没有说明). 经测试,STM32手册中的筛选器配置图错误,库函数的命名正确.参考 ...
- 检测到远端rexec服务正在运行中
0.系统 AIX7 1.先备份 /etc/inetd.conf文件 2.vi /etc/inetd.conf vi /etc/inetd.conf ##给原来的行加上注释# # exec .... / ...
- iOS 过滤字符串
//表示去掉字符串中的/符号 sysdate:[[self Gettime:strbegindate] stringByReplacingOccurrencesOfString:@"/&qu ...
- A表某字段==B表某字段 更新A表的数据
update mls_supplytask t1 -- 供应商认证任务 JOIN mls_sup_cert_report t2 -- 供应商认证报告 on t1.id = t2.certTaskId ...
- 建筑CAD软件如何设置当前默认层高?
在绘制CAD建筑图的过程中,必然少不了要对层高进行设置,如果每层的层高都一样,想要调整建筑CAD软件默认当前层高的话该如何设置?本节建筑CAD教程就和小编一起来了解一下浩辰CAD建筑软件中调整默认当前 ...