依赖属性实验案例一
来源:互联网 发布:淘宝网会员注册流程 编辑:程序博客网 时间:2024/05/18 09:17
目的:通过一个Student对象,实现前端两个TextBox输入值相同(此案例仅做实验,用于理解最简单的依赖属性用法,实际中不会这样用)
前端:
<Grid> <StackPanel> <TextBox x:Name="tbx" Width="100" Height="30" Background="LightBlue"/> <TextBox x:Name="tbx1" Width="100" Height="30" Background="LightBlue"/> </StackPanel> </Grid>
后台:
public partial class MainWindow : Window { Student stu = new Student(); public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { stu.Name = tbx.Text; Binding bd = new Binding(); bd.Path = new PropertyPath("Text"); //bd.ElementName = "tbx";//注意!!!Source和ElementName不能同时使用. bd.Source = tbx; bd.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(stu, Student.NameProperty, bd); Binding bd2 = new Binding(); bd2.Path = new PropertyPath("Name"); bd2.Source = stu; bd2.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(tbx1, TextBox.TextProperty, bd2); } } public class Student : DependencyObject { public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Student)); }
0 0
- 依赖属性实验案例一
- WPF属性(一)依赖属性
- ThinkPHP实验一 入门案例
- WPF中的属性(一)- CLR属性和依赖属性
- 一站式WPF--依赖属性(DependencyProperty)一
- 一站式WPF--依赖属性(DependencyProperty)一
- spring依赖注入方式一:属性注入
- 依赖属性(Dependency Properties)进阶(一)
- 一站式WPF--依赖属性(DependencyProperty)一
- WPF系列(一)依赖项属性
- 实验案例(一)打招呼(无跳转页面)
- 依赖属性
- 依赖属性
- 依赖属性
- 依赖属性
- 依赖属性
- 依赖注入简单案例
- Spring学习(一)加强 DI依赖注入的小案例
- java并发编程笔记
- 深度搜索DFS
- 类型转换
- 编译mahout使其支持hadoop2.6
- Spring @RequestMapping的用法
- 依赖属性实验案例一
- Android中的Shape使用总结
- ButterKnife使用
- 写了10+年的VC,现在根据公司需要,从头学习用C#做网站,用这里记下学习过程中的点点滴滴吧
- C语言实现异常处理(使用 setjmp 和 longjmp 函数)
- <弹弹弹>现已提交苹果申请,尽请期待!
- cocos2dx游戏开发之利用多点触摸(实现缩放功能或者简单的手势识别)
- LK光流算法中是怎么使用金字塔的(就一个截图,大概明白点就行,毕竟有函数不必自己实现)
- Android崩溃处理