绑定元素属性改变不通知界面

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

此时界面不会发生改变

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

 1   <Grid>
 2         <Grid.Resources>
 3             <local:PConverter x:Key="converter"/>
 4             <local:PointsConverter x:Key="pointsC"/>
 5
 6             <Style TargetType="Ellipse">
 7                 <Setter Property="Height" Value="5"/>
 8                 <Setter Property="Width" Value="5"/>
 9                 <Setter Property="HorizontalAlignment" Value="Left"/>
10                 <Setter Property="VerticalAlignment" Value="Top"/>
11             </Style>
12         </Grid.Resources>
13
14
15         <Grid.ColumnDefinitions>
16             <ColumnDefinition/>
17             <ColumnDefinition/>
18         </Grid.ColumnDefinitions>
19
20
21         <Grid x:Name="PathGrid" Grid.Column="0">
22             <Border BorderBrush="AliceBlue" BorderThickness="5"/>
23
24             <Path Stroke="BlueViolet" StrokeThickness="3">
25                 <Path.Data>
26                     <PathGeometry>
27                         <PathFigure StartPoint="{Binding ElementName=OwnerWindow,Path=StartPoint}">
28                             <PathFigure.Segments>
29                                 <PolyBezierSegment
30                                     IsSmoothJoin="True"
31                                     Points="{Binding ElementName=OwnerWindow,Path=Points,Converter={StaticResource pointsC},UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
32                             </PathFigure.Segments>
33                         </PathFigure>
34                     </PathGeometry>
35                 </Path.Data>
36             </Path>
37         </Grid>
38
39         <StackPanel Grid.Column="1">
40             <StackPanel>
41                 <Label>请输入StartPoint坐标</Label>
42                 <StackPanel Orientation="Horizontal">
43                     <Label>X:</Label>
44                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=XStartPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
45                     <Label>Y:</Label>
46                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=YStartPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
47                 </StackPanel>
48             </StackPanel>
49             <StackPanel>
50                 <Label>请输入EndPoint坐标</Label>
51                 <StackPanel Orientation="Horizontal">
52                     <Label>X:</Label>
53                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=XEndPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
54                     <Label>Y:</Label>
55                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=YEndPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
56                 </StackPanel>
57             </StackPanel>
58             <StackPanel>
59                 <Label>请输入路线经过的坐标点</Label>
60                 <StackPanel Orientation="Horizontal">
61                     <Label>X:</Label>
62                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=XPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
63                     <Label>Y:</Label>
64                     <TextBox Width="50" Text="{Binding ElementName=OwnerWindow,Path=YPoint,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
65                     <Button Height="20" Click="Button_Click">增加</Button>
66                 </StackPanel>
67             </StackPanel>
68
69             <ListBox  Height="100"
70                 ItemsSource="{Binding ElementName=OwnerWindow,Path=Points}"/>
71         </StackPanel>
72     </Grid>
  1 private ObservableCollection<Point> points = new ObservableCollection<Point>();
  2
  3         public ObservableCollection<Point> 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 YPoint
101         {
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<Point> 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     }

绑定元素属性改变不通知界面

时间: 2024-08-27 17:07:12

绑定元素属性改变不通知界面的相关文章

监听元素属性改变事件的方法

一.onchange事件只在键盘或者鼠标操作改变对象属性,且失去焦点时触发,脚本触发无效.(就是说你在输入框中输入完内容,输入完了,然后鼠标点别的地方触发该事件)二.oninput事件oninput 事件在用户输入时触发.不支持JS等赋值改变的元素属性.该事件在 <input> 或 <textarea> 元素的值发生改变时触发.(也就是说,不用输入完,边输入边触发该事件)①但是,这个方法是HTML5中的标准事件,IE9以下的浏览器是不支持oninput事件的.②使用时,还需要oni

silverlight属性改变事件通知

工作中遇到silverlight本身没有提供的某些属性改变事件,但又需要在属性改变时得到通知,Google搬运stack overflow,原地址 /// Listen for change of the dependency property public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) { //Bind t

jquery获取、改变元素属性值

//标签的属性称作元素属性,在JS里对应的DOM对象的对应属性叫DOM属性.JS里的DOM属性名有时和原元素属性名不同. //==================================操作元素属性================================== //返回元素指定属性值 var txt1_val=$("#txt1").attr("value"); //通过元素的DOM属性名更改DOM属性值 $("#txt1").att

sharepoint 2013 webservice 已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性

在调用webservice返回数据的时候,?出现以下错误: 已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性 这个就需要在调用webservice的解决方案中,在web.config或者app.config中配置一下: <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup&g

WCF 已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。

在做图片查询的时候,报错 已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性. 因为图片保存在数据库里,所以数据量比较大. WCF默认传输值是65536字节(64KB),这也太小了,我直接改成50M(52428800字节),网上说最大是支持2147483647字节,但是maxReceivedMessageSize属性是Long类型的,应该比这个还要大. 注意,只有TCP.IPC和基本的HTTP绑定才支持流操作,

WebService 之 已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。

在使用 WCF 中,遇到如下问题: 已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性. 问题说明: 客户端调用 WCF 返回数据量大时,局域网没有问题(客户现场发现一台机器有问题,具体原因不详.),发布到外网有问题. VS2012 Debug 捕获到的异常信息为:在 HTTP 通道上传输数据时发生错误(无法从传输连接中读取数据: 连接已关闭). WCFStorm 工具返回的异常为:已超过传入消息(65536)

已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。

错误:已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性. 或者 错误:反序列化操作“GetAllUserData”的响应消息的正文时出现错误.读取 XML 数据时,超出最大字符串内容长度配额 (8192).通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额. 行 1,位置 8834. 解决方案

VS+SqlServe 在引用了webservice后刷新数据时提示:已超过传入消息(65536)的最大消息大小配额若要增加配额请使用相应绑定元素上 MaxReceivedMessageSize 属性

使用了VS建立了webservice 后,在VS项目中添加了引用,可是在今天从sqlserve中取数据时, 突然提示:已超过传入消息(65536)的最大消息大小配额若要增加配额请使用相应绑定元素上 MaxReceivedMessageSize 属性 这让我那叫一个郁闷啊,之前都是一直好用,为什么突然就不好用了????????? 后来根据提示分析和上网查资料分析,猜测可能是数据量问题,再去找如何绑定元素上 MaxReceivedMessageSize属性,经过了几个小时的处理终于找到解决方案了:

Vue学习之路8-v-on指令学习简单事件绑定之属性

前言 上一篇文章以v-on指令绑定click事件为例介绍了v-on指令的使用方法,本文介绍一下v-on绑定事件的一些属性的使用方法. v-on绑定指令属性 .stop属性 阻止单击事件继续向上传播(简单点说就是不让父节点及父节点以上的节点事件触发),本示例如果没有stop属性,父节点和爷爷节点事件将会触发,并在控制台输出内容,示例代码和示例结果如下: 1 1 <template> 2 2 <div> 3 3 <p class="title1">{{t