实现INotifyPropertyChanged时出现问题

编程入门 行业动态 更新时间:2024-10-09 14:21:28
本文介绍了实现INotifyPropertyChanged时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好! 我已经看了很长时间的代码,以至于再也看不到它出了什么问题. 我有一个实现INotifyPropertyChanged的Survey类.与我的问题相关的两个属性是TotalPoints和TotalAdjustedPoints:

Hi everyone! I have been looking at my code for so long that I cannot longer see what is wrong with it. I have a class Survey that implements INotifyPropertyChanged. There are two properties relevant to my question, TotalPoints and TotalAdjustedPoints:

Public Property TotalPoints() As Long Get TotalPoints = lTotalPoints End Get Set(ByVal value As Long) If value <> lTotalPoints Then Me.lTotalPoints = value NotifyPropertyChanged("TotalPoints") End If End Set End Property Public Property TotalAdjustedPoints() As Long Get TotalAdjustedPoints = lTotalAdjustedPoints End Get Set(ByVal value As Long) If value <> lTotalAdjustedPoints Then Me.lTotalAdjustedPoints = value NotifyPropertyChanged("TotalAdjustedPoints") End If End Set End Property

我有一个ObservableCollection of Survey实例,用作列表视图的ItemsSource.列表视图是在XAML中定义的,如下所示:

I have an ObservableCollection of Survey instances that is used as ItemsSource for a list view. The listview is defined in XAML, like this:

<ListView Name="lvSurveyManagement" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Margin="5,5,5,5"> <ListView.View> <GridView> <GridViewColumn x:Name="colSurveyGUID" Width="300" DisplayMemberBinding="{Binding Path=SurveyGUID}"/> <GridViewColumn x:Name="colSurveyLineGUID" Width="100" DisplayMemberBinding="{Binding Path=LineGUID}"/> <GridViewColumn x:Name="colSurveyType" Width="100" DisplayMemberBinding="{Binding Path=SurveyType}"/> <GridViewColumn x:Name="colLoadedPoints" Width="122" DisplayMemberBinding="{Binding Path=TotalPoints}"/> <GridViewColumn x:Name="colAdjustedPoints" Width="122" DisplayMemberBinding="{Binding Path=TotalAdjustedPoints}"/> </GridView> </ListView.View> </ListView>

当我更新属于ObservableCOllection的Survey对象的上述属性时,TotalAdjustedPoints的更改会反映在列表视图中,而TotalPoints的更改则不会. 老实说,我看不到我在做什么,希望这里有人可以帮助我.预先谢谢您.

When I update the above mentioned properties for a Survey object belonging to the ObservableCOllection, the change in TotalAdjustedPoints is reflected in the listview, but the change in TotalPoints is not. I honestly don''t see what I am doing wrong, hope someone here can help me. Thank you in advance.

推荐答案

好吧...没什么比问问题来查看我的代码有什么问题了! 原来我正在更新这样的属性: Ok... nothing like asking the question to see what was wrong with my code! It turns out I was updating the properties like this: bDelete = Me.pSurvey.deleteSurveyPoints() If bDelete Then '... Me.pSurvey.TotalPoints = 0 'DOES NOT WORK Me.pSurvey.TotalAdjustedPoints = 0 'WORKS OK

但是问题是在Survey.deleteSurveyPoints内部,我有一行:

But the problem was that inside Survey.deleteSurveyPoints I had a line:

Me.lTotalPoints = 0

因此,值<> lTotalPoints(属性集)将永远不会被验证,PropertyChanged事件将永远不会被引发!

Hence value <> lTotalPoints (property set) would never be verified and the PropertyChanged event would never be raised!

更多推荐

实现INotifyPropertyChanged时出现问题

本文发布于:2023-11-05 10:06:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:INotifyPropertyChanged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!