0

Notes のコレクションを持つ Client エンティティがあります。

View に DataGrid があり、Client.AuditableNotes コレクションにデータバインドされています。メモがデータベースに既に存在する場合は、メモを確認できます。しかし、コレクションに新しい AuditableNote を追加しても表示されませんか?

私の ClientEditViewModel には、次の Client プロパティがあります。

    //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<AuditableNote> notes = new List<AuditableNote>();
                notes.Add(note);
                this.Client.AuditableNotes = notes;
            }
        }
        else
        {
             AuditableNote existingNote = this.Client.AuditableNotes.Where(an => an.AuditableNoteId == note.AuditableNoteId).First();
            existingNote = note;
        }
    }
}

私のDatagridは次のように定義されています:

<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}">
    <DataGrid.Columns>
        <DataGridTemplateColumn
            Header="Warning">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image x:Name="MyImage" Width="25" Height="20"/>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Warning}" Value="True">
                            <Setter Property="Source" TargetName="MyImage" Value="/Assets/Images/symbol_error.png"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Warning}" Value="False">
                            <Setter Property="Source" TargetName="MyImage" Value="/Assets/Images/symbol_information.png"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Note" Binding="{Binding Note, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="290"/>
        <DataGridTextColumn Header="Added By" Binding="{Binding AddedBy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
        <DataGridTextColumn Header="Date Added" Binding="{Binding DateAdded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
    </DataGrid.Columns>
</DataGrid>
4

0 に答える 0