【发布时间】:2019-07-29 09:39:10
【问题描述】:
ICollectionView 和 ObservableCollection<ItemVM>(目前)都从视图模型中公开:
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);
}
并且它们都绑定到ItemsSource 的DataGrid:
<StackPanel d:DataContext="{d:DesignInstance Type={x:Type vm:ItemsTestVM}}">
<DataGrid Name="DG1" ItemsSource="{Binding Items}"/>
<DataGrid Name="DG2" ItemsSource="{Binding ItemsView}"/>
</StackPanel>
虽然 both 在运行时显示项目,但只有 DG1(可观察绑定的)在设计时显示(三个虚拟)行。
为什么会这样?我该如何解决这个错误?
【问题讨论】:
标签: c# wpf xaml icollectionview