实现INotifyPropertyChanged时出现问题

实现INotifyPropertyChanged时出现问题

本文介绍了实现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.

推荐答案

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时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:47