2012-07-06 104 views
0

我必須在一個窗口中查看樹視圖。這兩個樹視圖都綁定到一個可觀察的集合「ReportStructure」。WPF Treeview更新

這兩個treeviews都顯示可觀察集合的樹狀層次結構。我使用了一個樹形視圖T1。選擇我想在第二個樹視圖T2中顯示的節點。

第一個treeview在每個葉子上都有複選框,當我檢查或取消選中一個葉子時,它會在T2中顯示或隱藏。爲了讓我這樣做,我不得不重新查詢綁定的CollectionView這樣

var IEquip = from eq in Report.Document.InspectionData.Equipments where eq.PartData.ReportIncluded = true 
        orderby eq.PartData.Order ascending 
        select eq; 


     EquipmentView = CollectionViewSource.GetDefaultView(IEquip); 
     EquipmentView.SortDescriptions.Add(
     new SortDescription("PartData.Order", ListSortDirection.Ascending)); 

的「ReportStructure」上面是Report.Document.InspectionData.Equipments。

我的問題是,當我再次查詢的datacontext爲T2 T1中的所有節點都倒塌

我我的XAML我已經設置updatesourcetrigger明確的,但它仍然崩潰。

<TreeView Grid.Row="5" IsEnabled="True" HorizontalContentAlignment="Stretch" Background="Transparent" BorderThickness="0" 
    ItemsSource="{Binding ReportStructure, UpdateSourceTrigger=Explicit}" HorizontalAlignment="Stretch" /> 

克隆將是一個解決方案,但後來我鬆散的方法可行更新從T1的信息T2,而沒有經過克隆

回答

0

我的理解是,樹型視圖不記得是否以前擴大了,只要你執行你的查詢?考慮將「IsExpanded」屬性添加到「Equipment」類中,然後讓TreeViewitem的IsExpanded屬性綁定到視圖模型的屬性。