1
votes

I'm trying to bind a WPF DataGrid to a ReactiveList. Unfortunately the bind don't show any row.

I tried to use a normal List as Datasource as well. I also tried the AutoGenerateColumn function and to use Binding to the properties(only getters, no setters) of AuswertungsEntry. But the properties never gotten accessed at runtime.

My view.xaml:

...

<DataGrid x:Name="AuswertungGrid" Grid.Row="1">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Fehler" Binding="{Binding Name}"></DataGridTextColumn>
        <DataGridTextColumn Header=" 1. Auswertung" Binding="{Binding ok1}"></DataGridTextColumn>
        <DataGridTextColumn Header=" 1. Auswahl"></DataGridTextColumn>
        <DataGridTextColumn Header=" 2. Auswertung"></DataGridTextColumn>
        <DataGridTextColumn Header=" 2. Auswahlt"></DataGridTextColumn>
        <DataGridTextColumn Header=" Gesamt"></DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

My binding in view.xaml.cs:

this.WhenActivated((d) =>
{                
    this.OneWayBind(ViewModel,
         viewModel => viewModel.Entries,
         view => view.AuswertungGrid.ItemsSource)
         .DisposeWith(d);
}

My ViewModel:

...
 private readonly ObservableAsPropertyHelper<ReactiveList<AuswertungsEntry>> _Entries;
 public ReactiveList<AuswertungsEntry> Entries => _Entries.Value;

 public AuswertungViewModel()
 {
    _Entries = this.WhenAnyValue(x => x.Data)
                   .Where(x => x != null)
                   .SelectMany(x => CreateDataSource())
                   .ToProperty(this, x => x.Entries);
 }

 public async Task<ReactiveList<AuswertungsEntry>> CreateDataSource()
 {
    return await AuswertungsService.GetAuswertung();
 }
...

The Service is returning correct Data. I checked that already. But no rows are getting generated, not with the GenerateAutoColumn feature nor manually.

I would expect, that DataGrid would get filled with the supplied data.

1
Did you confirm that CreateDataSource gets called? Please provide a minimal repo of your issue. - mm8
We deprecated ReactiveList, it sometimes doesn't do great with these sorts of scenario. Consider using a ObservableCollection, or a SourceList from DynamicData. - Glenn Watson
It may, ReactiveList doesn't properly support the INotifyCollectionChanged event, where it can send all the values in the range in one event. Hence one of the reasons why it was deprecated since a lot of the ItemsControl don't support range values that well. - Glenn Watson
@GlennWatson Thanks for your support, I changed my DataSource to be a SourceList and it is working. If you like you can change your comment to an answert so i will mark it as solved. - MrWhy
@mm8 thanks for your input. After I changed my DataSource to be a SourceList it worked - MrWhy

1 Answers

1
votes

ReactiveList<T> was deprecated a while back within the ReactiveUI project.

One of the issues is it doesn't produce INotifyCollectionChanged events in a way that WPF always expects, especially when you are adding ranged based values.

I would recommend you use a SourceList<T> if you need to mutate the data, or a ObservableCollection<T> otherwise.