Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagrid not updating when item added to ObservableCollection
    primarykey
    data
    text
    <p>I have a Client entity that has a collection of Notes. </p> <p>I have a DataGrid in my View that is databound to my Client.AuditableNotes collection and I can see the notes if they already exist in the database. However if I add a new AuditableNote into the collection it does not appear? </p> <p>My ClientEditViewModel has the following for my Client property:</p> <pre><code> //Backing Field private Client _client; . . . //Property public Client Client { get { return _client; } set { _client = value; RaisePropertyChanged("Client"); } } //Upon my NoteEdit usercontrol returning control back to clienteditviewmodel public void NoteEditFinished(AuditableNote note) { if (note != null) { note.AddedBy = _dbContext.SystemUsers.First(); if (note.AuditableNoteId == 0) { if (this.Client.AuditableNotes != null) { this.Client.AuditableNotes.Add(note); } else { List&lt;AuditableNote&gt; notes = new List&lt;AuditableNote&gt;(); notes.Add(note); this.Client.AuditableNotes = notes; } } else { AuditableNote existingNote = this.Client.AuditableNotes.Where(an =&gt; an.AuditableNoteId == note.AuditableNoteId).First(); existingNote = note; } } } </code></pre> <p>My Datagrid is defeined as so:</p> <pre><code>&lt;DataGrid Name="grdNotes" MinWidth="180" ItemsSource="{Binding Client.AuditableNotes, Mode=TwoWay}" AutoGenerateColumns="False" Background="Transparent" RowBackground="Transparent" IsReadOnly="True" SelectedItem="{Binding SelectedNote}" HorizontalScrollBarVisibility="Auto" DataContext="{Binding}"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Header="Warning"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Image x:Name="MyImage" Width="25" Height="20"/&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding Warning}" Value="True"&gt; &lt;Setter Property="Source" TargetName="MyImage" Value="/Assets/Images/symbol_error.png"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Warning}" Value="False"&gt; &lt;Setter Property="Source" TargetName="MyImage" Value="/Assets/Images/symbol_information.png"/&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;DataGridTextColumn Header="Note" Binding="{Binding Note, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="290"/&gt; &lt;DataGridTextColumn Header="Added By" Binding="{Binding AddedBy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/&gt; &lt;DataGridTextColumn Header="Date Added" Binding="{Binding DateAdded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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