Краткий обзор
- Нет элементов, отображаемых в моей таблице в графическом интерфейсе моего приложения
- Правильные столбцы отображаются в сетке при запуске (тип сбора данных)
- Событие CollectionChanged запускается на ObservableCollection, к которой привязана сетка
- Нет ошибки привязки в окне вывода (привязывается успешно, но не регистрирует делегата)
MyView.xaml
.
.
.
<UserControl.Resources>
<xcdg:DataGridCollectionViewSource
x:Key="items"
Source="{Binding Path=Items}"
AutoFilterMode="And" >
</xcdg:DataGridCollectionViewSource>
</UserControl.Resources>
<xcdg:DataGridControl
Name="dataGrid"
ReadOnly="True"
ItemsSource="{Binding Source={StaticResource items}}"
.
.
.
Конструктор MyView.xaml.cs
public MyView()
{
if (!DesignerProperties.GetIsInDesignMode(this))
DataContext = new MyViewModel().Tree;
initializeComponent();
}
Ключевые части MyViewModel.cs
public MyTree Tree { get; set; }
public MyViewModel()
{
Tree = new MyTree();
}
Ключевые части MyTree.cs
public ObservableCollection<Item> Items{ get; private set; }
public MyTree()
{
Items= new ObservableCollection<Item>();
Items.CollectionChanged += delegate { Console.WriteLine("Trigger"); };
}
Триггер печатается при каждом добавлении и удалении, но пользовательский интерфейс все еще думает, что коллекция пуста и не знает ообновления.Без моего дополнительного делегата Items.CollectionChanged
равняется null
(т.е. проанализированный Xaml не приводит к добавлению слушателя в коллекцию)
- Что я делаю неправильно, пытаясь связать свой
DataGridCollectionViewSource
в коллекцию ObservableCollection?
Рад сообщить больше подробностей, я попытался абстрагироваться от своего варианта использования до сути проблемы.Вложение коллекции может показаться смешным, но в основном это набор узлов в дереве для более быстрого доступа.
Заранее спасибо!
РЕДАКТИРОВАТЬ
Добавив PresentationTraceSources.TraceLevel=High
к моему Xaml, я получил более подробный вывод.
ItemsSource="{Binding Source={StaticResource orders}, PresentationTraceSources.TraceLevel=High}"
Здесь я думаю, что проблема в том, что Default update trigger resolved to PropertyChanged
, где я ожидаю, что значение по умолчанию будет CollectionChanged
.Я все еще не знаю, что с этим делать.
BindingExpression (hash=43320496): Default mode resolved to OneWay
BindingExpression (hash=43320496): Default update trigger resolved to PropertyChanged
BindingExpression (hash=43320496): Attach to Xceed.Wpf.DataGrid.DataGridControl.ItemsSource (hash=9150720)
BindingExpression (hash=43320496): Resolving source
BindingExpression (hash=43320496): Found data context element: <null> (OK)
BindingExpression (hash=43320496): Use View from DataGridCollectionViewSource (hash=9026257)
BindingExpression (hash=43320496): Activate with root item <null>
BindingExpression (hash=43320496): Replace item at level 0 with <null>, using accessor {DependencyProperty.UnsetValue}
BindingExpression (hash=43320496): GetValue at level 0 from <null> using <null>: <null>
BindingExpression (hash=43320496): TransferValue - got raw value <null>
BindingExpression (hash=43320496): TransferValue - using final value <null>
BindingExpression (hash=43320496): Got PropertyChanged event from DataGridCollectionViewSource (hash=9026257) for View
BindingExpression (hash=43320496): Deactivate
BindingExpression (hash=43320496): Replace item at level 0 with {NullDataItem}
BindingExpression (hash=43320496): Use View from DataGridCollectionViewSource (hash=9026257)
BindingExpression (hash=43320496): Activate with root item DataGridCollectionView (hash=54545236 Count=0)
BindingExpression (hash=43320496): Replace item at level 0 with DataGridCollectionView (hash=54545236 Count=0), using accessor {DependencyProperty.UnsetValue}
BindingExpression (hash=43320496): GetValue at level 0 from DataGridCollectionView (hash=54545236 Count=0) using <null>: DataGridCollectionView (hash=54545236 Count=0)
BindingExpression (hash=43320496): TransferValue - got raw value DataGridCollectionView (hash=54545236 Count=0)
BindingExpression (hash=43320496): TransferValue - using final value DataGridCollectionView (hash=54545236 Count=0)