2013-04-03 89 views
0

我有一個UI元素,它是一個列表視圖,其中包含另一個列表視圖(一個垂直和一個水平)。即使使用INotifyPropertyChanged接口,ListView也不會更新

第一個listview的Itemsource是一個ObservableCollection對象,它依次包含一個子對象的ObservableCollection。兩者都實現了INotifyPropertyChanged接口,並在有用時調用PropetyChanged事件。

如果我添加新的子對象,我會看到我的第二個listview更新,但是當我更改一個值時,我沒有看到任何更改。在這種情況下,我有什麼要刷新我的UI元素嗎?

這裏是我的列表視圖

<ListView x:Name="LstInfoEtape" Margin="0,0,0,0" Style="{StaticResource BaseListView}" Grid.Row="2" Grid.Column="1" > 
<ListView.ItemTemplate> 
    <DataTemplate> 
    <ListView x:Name="LstEtape" ItemsSource="{Binding LstEtapes}" Background="#00000000" SelectionChanged="ListView_SelectionChanged" ScrollViewer.ScrollChanged="ListView_ScrollChanged"> 
    <ListView.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Horizontal" /> 
    </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.ItemTemplate> 
    <DataTemplate> 
     <Border Width="82" CornerRadius="4" BorderBrush="{Binding ColorSelected}" BorderThickness="3,3,3,3" Visibility="{Binding EtapeVisible}" Background="{Binding ColorBackground}" MouseDown="Border_MouseDown"> 
     <Grid Width="80" > 
     <Grid.RowDefinitions> 
     <RowDefinition Height="19"/> 
     </Grid.RowDefinitions> 
     <TextBlock Margin="2,0,2,0" x:Name="TxtDateRappel" TextWrapping="Wrap" Grid.Row="0" Text="{Binding DateRappelTerminaison,StringFormat=yyyy-MM-dd,NotifyOnSourceUpdated=True}" Visibility="{Binding EtapeVisible}" FontSize="12" Foreground="{Binding ColorForeground}" /> 
     </Grid> 
     </Border> 
    </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 
    </DataTemplate> 
</ListView.ItemTemplate> 
</ListView> 

我使用的類是那些

​​

這裏是函數(還有更多的處理來獲得項目的集合,但我懷疑這是真的相關:

Private Sub LoadList(colSuivi as ObservableCollection(Of SuiviProductionLite) 
    LstInfoEtape.ItemsSource = colSuivi 
End Sub 

Private Sub Border_MouseDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) 
    Dim oBorder As Border 


    Dim oEtapeLite As DAL.ContratProcessusEtapeLite 

    Select Case e.Source.GetType.ToString 
     Case "System.Windows.Controls.TextBlock" 
      Dim oTxt As TextBlock = e.Source 
      Dim oGrid As Grid = oTxt.Parent 
      _oCurBorderDet = oGrid.Parent 
     Case "System.Windows.Controls.Border" 
      Dim oBrd As Border = e.Source 
      _oCurBorderDet = e.Source 
    End Select 

    If Not _oCurBorderDet.DataContext.GetType().FullName.Equals("MS.Internal.NamedObject") Then 
     oEtapeLite = _oCurBorderDet.DataContext 
     oEtapeLite.Selected = True    
    End If 


End Sub 

當我做一些跟蹤時,我知道這兩個PropertyChanged事件打電話給我點擊我的用戶界面。如果我做一個手動的「Items.Refresh」,我也可以看到UI被更改,但是我想刪除手動刷新,因爲它刷新了所有內容,不僅僅是剛剛修改的項目,當面對大量數據時,更多時間。

+2

發佈您的代碼。否則,這都是猜測。 – 2013-04-03 20:32:16

+0

並將該XAML移動到左側 – Paparazzi 2013-04-03 20:47:09

回答

1

我看到一個問題

Public Property IdClientContratSequenceTravail() As Long 
    Get 
     Return _lngIdSequenceTravail 
    End Get 
    Set(ByVal value As Long) 
     _lngIdSequenceTravail = value 
     NotifyPropertyChanged("IdSequence") 
    End Set 
End Property 

錯誤的名稱在通知

+0

Notify裏面的名稱是否真的有所作爲? – 2013-04-04 12:04:11

+0

所以你是對的。 Notify中的名稱是錯誤的。另外我可能會補充說,因爲我試圖看到的變化是在ReadOnly Property中,我還在屬性中添加了一個Notify,它影響了只讀屬性,現在它工作。 – 2013-04-04 12:11:12

相關問題