Note that there are some explanatory texts on larger screens.

plurals
  1. POObservableCollection binding in WPF
    primarykey
    data
    text
    <p>I have a ObservableCollection which holds records of custom type Item. I use that collection as a binding for a ListView in WPF. That class Item also implements the interface INotifyPropertyChanged. When I update some of the records in the ListView, I can see the change in the ListView. </p> <p>All this data comes from a WCF service. When I call the client object for the service and call a delete method to delete an item that belongs to the ObservableCollection, the record gets deleted in the DB but the items in the ListView are not updated. Is this how it is supposed to work, or should I remove the item from the collection manually when I delete it from the DB with the service call?</p> <p>Thanks</p> <p>Here is the XAML:</p> <pre><code>&lt;ListView ItemsSource="{Binding AllItems}" Height="244" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" Margin="1,25,0,0" Name="listView1" VerticalAlignment="Top" Width="485" &gt; &lt;ListView.ContextMenu&gt; &lt;ContextMenu AllowDrop="False"&gt; &lt;MenuItem Name="openRecord" Header="Open" Click="ContextMenuItem_Click" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" /&gt; &lt;MenuItem Name="deleteRecord" Header="Delete" Click="ContextMenuItem_Click" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" /&gt; &lt;/ContextMenu&gt; &lt;/ListView.ContextMenu&gt; &lt;ListView.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type ListViewItem}"&gt; &lt;EventSetter Event="MouseDoubleClick" Handler="list_UserItems_ItemMouseDoubleClick" /&gt; &lt;/Style&gt; &lt;/ListView.ItemContainerStyle&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Title}" Header="Title" Width="200" /&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding CreatedByName}" Header="Created By" Width="100" /&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding CreatedOn}" Header="Created On" Width="100" /&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding ExpirationDate}" Header="Expires" Width="100" /&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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