1

I have both ICollectionView and ObservableCollection<ItemVM> (for now) exposed from view model:

public ICollectionView ItemsView
{
    get => !IsInDesignMode ? _itemsView :
            CollectionViewSource.GetDefaultView(new ObservableCollection<Item>());
    set => Set(ref _itemsView, value));
}

public ObservableCollection<Item> Items
{
    get => _items;
    private set => Set(ref _items, value);
}

and both of them are bound to ItemsSource of a DataGrid:

<StackPanel d:DataContext="{d:DesignInstance Type={x:Type vm:ItemsTestVM}}">
    <DataGrid Name="DG1" ItemsSource="{Binding Items}"/>
    <DataGrid Name="DG2" ItemsSource="{Binding ItemsView}"/>
</StackPanel>

while both display items in runtime, only the DG1 (observable-bound one) display (three dummy) rows in design-time.
Why is that and how can I fix this error?

wondra
  • 3,271
  • 3
  • 29
  • 48

1 Answers1

0

From what you have shown, it silently works...for the design time logic does not return a viable data set to show; just an empty observable collection.

In design mode only, an empty view is returned because there is no association between any (design time) existing data that you must be doing as in the Items property (which works).

Look at the creation of the view...where is the observable collection getting data?

  CollectionViewSource.GetDefaultView(new ObservableCollection<Item>())
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122