Note that there are some explanatory texts on larger screens.

plurals
  1. POAn ItemsControl is inconsistent with its items source - happening in nested ListView
    text
    copied!<p>This given page shows all cities for a particular state. I am displaying a ListView within a ListView. The outer ListView shows a listing of cities. The inner ListView shows all notes attached to each particular city.</p> <p>Everything loads up properly. I can add a note, which gets added to the database. However, after adding a note, clicking the scroll bar in the NotesListView causes the exception: </p> <blockquote> <p>An ItemsControl is inconsistent with its items source</p> </blockquote> <p>I understand the problem...the listing of notes attached to the ListView becomes out of sync, after I add a note to the city.Notes property in the viewmodel... But how do I force this ListView to refresh?</p> <p>Here is my XAML (edited for brevity):</p> <pre><code>&lt;ListView x:Name="CityListView" ItemsSource="{Binding CityDetails, Mode=OneWay}"&gt; &lt;!--City Name and other city details. go here--&gt; &lt;ListView x:Name="NotesListView" ItemsSource="{Binding Notes}"&gt; &lt;TextBlock Text="{Binding Path=Note}" /&gt; &lt;/ListView&gt; &lt;StackPanel&gt; &lt;TextBlock Text="Add Note:" /&gt; &lt;TextBox Text="{Binding Path=DataContext.Note, RelativeSource={RelativeSource AncestorType=UserControl}}" /&gt; &lt;Button Content="ADD NOTE" Command="{Binding Path=DataContext.AddNoteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding}" /&gt; &lt;/StackPanel&gt; &lt;/ListView&gt; </code></pre> <hr> <p>Here is the AddNote() method in the ViewModel that is hooked into the AddNoteCommand:</p> <pre><code>Protected _stateService As IStateService Protected _state As State Protected Sub OnAddNote(city As City) Dim note As Note = Nothing If Not String.IsNullOrWhiteSpace(Me.Note) Then note = New Note() With { .Note = Me.Note, .NoteDate = DateTime.Now, } city.Notes.Add(note) _stateService.SaveExistingState(_state) ' this saves the note, since _state contains: ' Property Cities As ICollection(Of City) ' and the city object passed into this method belongs to that collection... RaisePropertyChanged(Function() city.Notes) End If End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload