快速彙總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