0

Trying to update a "Details" DataGrid RowDetailsTemplate in a "People" DataGrid(Doing some crazy Inception stuff!).

The collection is being updated correctly with NotifyOfPropertyChange(), but it doesn't seem to update the row in the DataGrid.

The Header "Adress Info" is there in the RowDetailsTemplate, but no rows are showing up in that DataGrid.

Models:

public class PersonModel
{
  public string FirstName{ get; set; }
  public string LastName{ get; set; }
}

public class DetailsModel
{
  public string Address{ get; set; }
}

ViewModel:

private ObservableCollection<PersonModel> _people;
private ObservableCollection<PersonModel> People
    {
        get { return _people; }
        set 
        {
            _people = value;
            NotifyOfPropertyChange(() => People);
        }
    }

private ObservableCollection<DetailsModel> _details;
private ObservableCollection<DetailsModel> Details
    {
        get { return _details; }
        set 
        {
            _details = value;
            NotifyOfPropertyChange(() => Details);
        }
    }

public void SetRowDetail(PeopleModel selectedPerson)
    {
        PeopleModel person = selectedPerson;

        DetailsModel detailInfo = new DetailsModel();
        detailInfo.address = GetAddr(person.AddressIndex);
            
        Details = new ObservableCollection<DetailsModel>() {detailInfo};
    }

View:

<DataGrid x:Name="People"
          Grid.Row="1"
          cm:Message.Attach="[Event MouseUp]=[Action SetRowDetail($this)]">
          <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBox Text="Person Details" />
                    <DataGrid x:Name="Details"
                              ItemsSource="{Binding TakeoutCoefficients}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Address Info"
                                                Binding="{Binding Address, UpdateSourceTrigger=PropertyChanged}" />
                        </DataGrid.Columns>
                    </DataGrid>
                </StackPanel>
            </DataTemplate>
          </DataGrid.RowDetailsTemplate>
</DataGrid>

I would like to achieve this without having to take out the RowDetailsTemplate.

Tried BindableCollection and ItemsSource doesn't seem to help either.

Any help or suggestions would be greatly appreciated.

Corey
  • 835
  • 1
  • 9
  • 32
  • Setup `ItemsSource` for `DataGrid`, bind it to the collection property, and use `ObservableCollection` as storage not `BindableCollection` – aepot Jul 10 '20 at 19:25
  • @aepot Thanks for the suggestions. I tried both, but doesn't fix anything for me. I've edited the question with your suggestions. Let me know if you had a different idea of how to solve this. – Corey Jul 10 '20 at 21:12
  • Where's `ItemsSource` for the parent `DataGrid`? e.g. `{Binding People}`. Why do you need embedded `DataGrid`? – aepot Jul 10 '20 at 21:34
  • Guessing that `Details` property must be inside of `PersonModel` and `PersonModel` can implement `INotifyPropertyChanged` (using your MVVM library). Then outer `DataGrid.ItemsSorce` may be bind to `People` and inner `DataGrid.ItemsSorce` to `Details`. – aepot Jul 10 '20 at 21:45
  • @aepot With `Caliburn.Micro` mvvm you can just have `x:Name` act like the `ItemsSource`. I need the embedded `DataGrid` because the real data I have has a lot more properties than the one I have here in the example. It will change based on what row is selected in the parent `DataGrid`. – Corey Jul 10 '20 at 22:07
  • Ah, ok. Billions of tangled frameworks. I'm pretty old and using pure WPF. :) You may move `Details` inside the `PersonModel` then. Embedded `DataGrid` will pick correct items on row change automatically because inside row `Binding` source (`DataContext`) is set to the selected row's item, not to parent VM. Child table doesn't see the property now. – aepot Jul 10 '20 at 22:18
  • @aepot I think you're right, I'm probably over complicating things by separating the 'details'. – Corey Jul 10 '20 at 23:13

0 Answers0