博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
绑定元素属性改变不通知界面
阅读量:4502 次
发布时间:2019-06-08

本文共 6310 字,大约阅读时间需要 21 分钟。

原文:

情景假设:绑定的是一个Point,当Point的X或者Y属性发生改变时,绑定的点也随界面改变

此时界面不会发生改变

原因:当X或者Y属性发生改变时并没有触发Point的Set方法

 

1   
2
3
4
5 6
12
13 14 15
16
17
18
19 20 21
22
23 24
25
26
27
28
29
32
33
34
35
36
37
38 39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 69
71
72
1 private ObservableCollection
points = new ObservableCollection
(); 2 3 public ObservableCollection
Points 4 { 5 get { return points; } 6 set{points = value;} 7 } 8 9 10 11 12 13 14 public Point StartPoint 15 { 16 get { return (Point)GetValue(StartPointProperty); } 17 set { SetValue(StartPointProperty, value); } 18 } 19 20 // Using a DependencyProperty as the backing store for StartPoint. This enables animation, styling, binding, etc... 21 public static readonly DependencyProperty StartPointProperty = 22 DependencyProperty.Register("StartPoint", typeof(Point), typeof(PathAnimationDemo), new PropertyMetadata(new Point(0, 0))); 23 24 25 26 public Point EndPoint 27 { 28 get { return (Point)GetValue(EndPointProperty); } 29 set 30 { 31 SetValue(EndPointProperty, value); 32 this.OnPropertyChanged("EndPoint"); 33 } 34 } 35 36 // Using a DependencyProperty as the backing store for EndPoint. This enables animation, styling, binding, etc... 37 public static readonly DependencyProperty EndPointProperty = 38 DependencyProperty.Register("EndPoint", typeof(Point), typeof(PathAnimationDemo), new PropertyMetadata(new Point(100, 100))); 39 40 private double xStartPoint; 41 42 public double XStartPoint 43 { 44 get { return this.StartPoint.X; } 45 set 46 { 47 xStartPoint = value; 48 this.StartPoint = new Point(xStartPoint, this.StartPoint.X); 49 } 50 } 51 52 53 private double yStartPoint; 54 55 public double YStartPoint 56 { 57 get { return this.StartPoint.Y; } 58 set 59 { 60 yStartPoint = value; 61 this.StartPoint = new Point(this.StartPoint.X, yStartPoint); 62 } 63 } 64 65 private double xEndPoint; 66 67 public double XEndPoint 68 { 69 get { return this.EndPoint.X; } 70 set 71 { 72 xEndPoint = value; 73 this.EndPoint = new Point(xEndPoint, this.EndPoint.Y); 74 } 75 } 76 77 private double yEndPoint; 78 79 public double YEndPoint 80 { 81 get { return this.EndPoint.Y; } 82 set 83 { 84 yEndPoint = value; 85 this.EndPoint = new Point(this.EndPoint.X, yEndPoint); 86 } 87 } 88 89 90 private double xPoint; 91 92 public double XPoint 93 { 94 get { return xPoint; } 95 set { xPoint = value; } 96 } 97 98 private double yPoint; 99 100 public double YPoint101 {102 get { return yPoint; }103 set { yPoint = value; }104 }105 106 107 108 109 public PathAnimationDemo()110 {111 this.SetPoints(this.points);112 InitializeComponent();113 114 }115 116 private void SetPoints(ObservableCollection
myPointCollection)117 {118 points.Add(new Point(50, 100));119 myPointCollection.Add(new Point(100, 50));120 myPointCollection.Add(new Point(200, 100));121 myPointCollection.Add(new Point(100, 200));122 myPointCollection.Add(new Point(400, 400));123 myPointCollection.Add(new Point(600, 600));124 }125 126 public event PropertyChangedEventHandler PropertyChanged;127 128 private void OnPropertyChanged(string propertyName)129 {130 if (PropertyChanged != null)131 {132 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));133 }134 }135 136 private void Button_Click(object sender, RoutedEventArgs e)137 {138 this.points.Add(new Point(this.xPoint, this.YPoint));139 this.Points = this.points;140 }141 142 }

 

 

posted on
2018-08-14 10:09 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lonelyxmas/p/9472903.html

你可能感兴趣的文章
jQuery插件实现网页底部自动加载-类似新浪微博
查看>>
学生空间bug report
查看>>
shanchushanchu
查看>>
linux下使用autoconf制作Makefile
查看>>
快来秒杀我
查看>>
Python_阻塞IO、非阻塞IO、IO多路复用
查看>>
爬虫超时解决的方法
查看>>
网络技术和科技革命周末随想
查看>>
Codeforces 10C Digital Root 法冠军
查看>>
华为-on演习--身高找到最好的二人
查看>>
debian软件安装基础(同tomcat案件)
查看>>
如何面对客户的紧急需求
查看>>
【转载】嵌入式linux学习规划
查看>>
[转帖]和机器学习和计算机视觉相关的数学
查看>>
mp4格式(转帖加修改) 转载
查看>>
JAVA类加载和初始化
查看>>
SMTP发送邮件
查看>>
关于句柄
查看>>
java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
查看>>
Vue学习之路第十七篇:全局过滤器的使用
查看>>