当前位置:网站首页>WPF数据驱动修改绑定的方法
WPF数据驱动修改绑定的方法
2022-04-21 21:47:00 【亿速云】
WPF数据驱动修改绑定的方法
本篇内容介绍了“WPF数据驱动修改绑定的方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
一、简介
在XAML文件中我们创建了一个TextBlock 和一个Slider。2个控件。我们把TextBlock的Text属性(用于显示文本的属性)设置为{Binding Intelligence}。把Slider的Value属性(滑块的当前值)设置为{Binding Intelligence}。
二、代码案例
XMAL:
<Grid> <StackPanel> <TextBlock Text="{Binding Intelligence}"/> <!--通过数据驱动修改绑定值得属性--> <TextBox Text="{Binding Intelligence,Mode=TwoWay}"/> <Slider Minimum="1" Maximum="100" Value="{Binding Intelligence}"/> <StackPanel Orientation="Horizontal"> <TextBlock Text="名称:"/> <TextBlock Text="{Binding Name}" MinWidth="120"/> <TextBlock Text="请输入需要修改的名称:"/> <TextBox MinWidth="120" x:Name="tb_inputName"/> </StackPanel> <!--通过事件驱动修改绑定值得属性--> <Button Content="事件驱动修改绑定值。" Click="AlertText_Click"/> </StackPanel> </Grid>
后台逻辑:
public partial class MainWindow : Window { Person p; public MainWindow() { InitializeComponent(); p = new Person(); Binding binding = new Binding(); binding.Source = p; binding.Mode = BindingMode.TwoWay; binding.Path = new PropertyPath("Name"); BindingOperations.SetBinding(tb_inputName, TextBox.TextProperty, binding); this.DataContext = p; } private void AlertText_Click(object sender, RoutedEventArgs e) { p.Name = "点击按钮后>>>>"; } } public class Person : INotifyPropertyChanged { private double _intelligence; public double Intelligence { get { return _intelligence; } set { _intelligence = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Intelligence")); } } private string _name; public string Name { get { return _name; } set { _name = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name")); } } public event PropertyChangedEventHandler PropertyChanged; }
三、运行效果



“WPF数据驱动修改绑定的方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
版权声明
本文为[亿速云]所创,转载请带上原文链接,感谢
https://www.yisu.com/zixun/694277.html
边栏推荐
- 短视频直播模式让偏远地区农产品“走出去”
- 【用例级别定义】
- 2022r1 quick opening pressure vessel operation certificate examination question bank simulation examination platform operation
- 【题解】[SDOI2012] 吊灯
- JVM自定义类加载器在代码扩展性的实践
- 力扣解法汇总824-山羊拉丁文
- Introduction to qmenqu
- 想要从数字化转型获得收益,你该怎么做?
- 清洁机器人--红外下视传感器,检测是否存在地面距离突变的情形
- Common network tools 4: SG broadband tools
猜你喜欢

User manual for visual view of data source of easybi reporting system

分析师认为三星Galaxy Z Fold 4和Z Flip 4可能比其前代产品更便宜

MySQL fuzzy search and proofreading rules

UML之一综合设计例题

外包学生管理系统的架构文档

Architecture document of student management system

Eeasybi report system data source selection code development manual

危机四伏,卡士酸奶的高端人设还立得住吗?

【测试用例级别定义】

Introduction to qmenqu
随机推荐
Unity tips
Operation instructions of archives management system
Successful cases of project management system development
[UML operation contract]
Keil Package常用芯片高速下载地址,含历史版本,快关注我速速收藏
Architecture document of student management system
Authing 正式加入 W3C 组织,将参与相关国际标准制定
MySQL is the most complete arrangement (interview questions + Notes + Guide Map), and the big interview companies are no longer stumped by mysql
helm安装jenkins(官方)
Use try-with-resources or close this “FileOutputStream“
【C语言进阶9——指针的进阶(6)- 回调函数】
Hospital-Oriented RFID Service
OA form design case display
Automatically generate SQL excluding a field
分析师认为三星Galaxy Z Fold 4和Z Flip 4可能比其前代产品更便宜
【SeMask】Semantically Masked Transformers for Semantic Segmentation
IDEA通过Jedis操作Linux上的Redis;Failed to connect to any host resolved for DNS name问题
[common shortcut keys]
JS to realize automatic scrolling of announcements
【编程时适合的音乐】