Hello,
I have a datagrid on two levels, I manage to update my UI for the first datagrid, but i have a problem for the second one.
Although I can update the properties in the grid, when i want to remove/add a new row (with an observablecollection), the UI is not updating while the collection is modified.
I think the issue comes from the datacontext of the the second grid, but I have no more ideas that I haven't tried to make this thing work...
Here is my simplified code to illustrate the problem:
XAML:
<controls:DataGrid
x:Name="Maingrid"
IsReadOnly="True"
ItemsSource="{x:Bind ViewModel.Source, Mode=OneWay}">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="p1" Binding="{Binding p1}" IsReadOnly="True"/>
<controls:DataGridTextColumn Header="p2" Binding="{Binding p2}" IsReadOnly="True"/>
</controls:DataGrid.Columns>
<controls:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<controls:DataGrid
x:Name="RowDatagrid"
ItemsSource="{Binding Path=Source2, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="p3" Binding="{Binding p3}" IsReadOnly="True"/>
<controls:DataGridTextColumn Header="p4" Binding="{Binding p4}" IsReadOnly="True"/>
</controls:DataGrid.Columns>
</controls:DataGrid>
</Grid>
</StackPanel>
</DataTemplate>
</controls:DataGrid.RowDetailsTemplate>
</controls:DataGrid>
ViewModel:
public class TestObjectViewModel : INotifyPropertyChanged
{
public ObservableCollection<TestObject> Source { get; set; } = new ObservableCollection<TestObject>();
...
}
First datagrid object:
public class TestObject : INotifyPropertyChanged
{
public string p1 { get; set; }
public int p2 { get; set; }
public ICollection<TestObjectDetail> Source2 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string isAsigned = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(isAsigned));
}
}
Second datagrid object:
public class TestObjectDetail : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public int p3 { get; set; }
public int p4 { get; set; }
...
}
Thank you in advance for your help.