快速汇总WPF - 的ObservableCollection绑定失败 - .NET 4.0
- 没有项目在我在我的应用
- 正确列在格列时,它会调用的GUI网格显示(拿起集合型)
- 在网格上被绑定到
- 在输出窗口中没有结合错误的ObservableCollection CollectionChanged事件触发(绑定成功但未注册代表)
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键Pa RTS
public ObservableCollection<Item> Items{ get; private set; }
public MyTree()
{
Items= new ObservableCollection<Item>();
Items.CollectionChanged += delegate { Console.WriteLine("Trigger"); };
}
触发被印在每一个添加和删除,但UI仍然认为收藏是空的,不知道的更新。如果没有我的额外委托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)
注意评论一些答案? – VVS 2010-11-29 21:21:01