私はツリービューを持っています。私がWCFメソッドを使って動的に構築するSL 4アプリケーションでは、ツリービューは、フォルダとドキュメントで構成されています。文書のバッチが追加されたときにツリーを再構築できるようにする必要があります。階層のあるSilverlightツリービューをクリアする
SLツリービューからすべてのアイテムをクリアするにはどうすればいいですか?TreeView.Items.Clear()
は動作しないため、このことを言ってはいけません。また、すべてのアイテムとその子を削除するためにループforeach
を使用することは不可能です。私は記事hereと言っていますが、どこでもTreeView.Children.Copy
またはTreeView.Items.Copy
は表示されません。これは私が試した最後のものですが、私は迷っています...
これを行う方法を知っていればお知らせください...ありがとう!
Private Sub NewDocumentTree_Received(ByVal sender As Object, ByVal e As GetDocumentTreeCompletedEventArgs)
Me.ThisDocTreeView = e.Result
ClearTree()
PopulateDocTreeView()
End Sub
Private Sub ClearTree()
Dim tempTree As New TreeView()
tempTree = CopyTreeViewToNewObject(Me.docTreeView)
For Each tvi As TreeViewItem In tempTree.Items
For Each sub_tvi As TreeViewItem In tvi.Items
For Each d_tvi As TreeViewItem In sub_tvi.Items
RemoveTreeViewSubItems(d_tvi)
Next
RemoveTreeViewSubItems(sub_tvi)
Next
RemoveTreeViewSubItems(tvi)
Next
tempTree.UpdateLayout()
Me.docTreeView = tempTree
Me.docTreeView.UpdateLayout()
End Sub
Private Sub RemoveTreeViewSubItems(ByVal tvi As TreeViewItem)
For Each sub_tvi As TreeViewItem In tvi.Items
tvi.Items.Remove(sub_tvi)
tvi.UpdateLayout()
Next
End Sub
Private Function CopyTreeViewToNewObject(ByVal treeview As TreeView) As TreeView
Dim newTree As New TreeView()
For Each Parent As TreeViewItem In treeview.Items
newTree.Items.Add(GetTreeViewItemAndChildren(Parent))
Next
Return newTree
End Function
Private Function GetTreeViewItemAndChildren(ByVal treeViewItem As TreeViewItem)
Dim ParentalItem As New TreeViewItem
ParentalItem = treeViewItem
For Each child As TreeViewItem In treeViewItem.Items
Dim firstChild As New TreeViewItem
firstChild = child
For Each subChild As TreeViewItem In child.Items
Dim secondChild As New TreeViewItem
secondChild = child
firstChild.Items.Add(secondChild)
Next
ParentalItem.Items.Add(firstChild)
Next
Return ParentalItem
End Function
UPDATE:ここに私のWCFツリーへのバッチ更新のサービス、およびツリービューを構築する主な方法から通知を受ける方法があります。
Private Sub NewDocumentTree_Received(ByVal sender As Object, ByVal e As GetDocumentTreeCompletedEventArgs)
Me.ThisDocTreeView = e.Result
Me.docTreeView.Items.Clear()
Me.docTreeView.UpdateLayout()
PopulateDocTreeView()
End Sub
Private Sub PopulateDocTreeView()
'ensure all items are clear
Me.docTreeView.Items.Clear()
'loop through root folder to extract parent "user" folders, and examine sub folders
For Each folder As PortalOnline.PortalDocRootFolder In ThisDocTreeView.RootFolders
'get this users folder as a tree view items
Dim parent As TreeViewItem = GetParentTreeViewFolder(folder)
'define a new list of category folders based on this users documents
Dim catFolders As List(Of TreeViewItem) = GetCategoryFolderList(folder)
'loop through the subfolders of the users parent folder for document and get each document folder
'as a new tree view item
For Each child As PortalOnline.PortalDocInfo In folder.SubFolders
'define the document tree view item
Dim childItem As TreeViewItem = GetDocumentTreeItem(child, folder)
'loop through the category folders, and add the document tree view item to the appropriate folder
For Each categoryfolder As TreeViewItem In catFolders
Dim childMeta As DocTreeViewItem = childItem.Tag
'if the category tree veiw item head matches the document category of the document tree view item
'then add the document tree view item into that category folder
If categoryfolder.Header = childMeta.DocumentCategory Then
categoryfolder.Items.Add(childItem)
End If
Next
Next
'add all category folders to the users parent folder
For Each subfolder As TreeViewItem In catFolders
parent.Items.Add(subfolder)
Next
'add the users parent folder to the tree view
docTreeView.Items.Add(parent)
Next
End Sub
ツリービューを明らかにWCFは、パブリッシュおよび更新ページのロード時、及びNewDocumentTree_Receivedメソッドが呼び出されたときに移入されています。
インスタンス内ERROR: ツリーがクリアされ、更新、または他のツリーが最初に移入ないとされていないことを私に伝えます
を「同じキーを持つ項目がalread追加されました」うまくいけば助けは状況を明らかにする。
注:PopulateTreeView()メソッドは、Me.docTreeView.Items.Clear()で始まります。 – wakurth
'treeView.Items.Clear()'が機能しない理由を説明できますか?それはエラーを出すか、すべてのアイテムをクリアするものではないのですか?私は一緒に簡単なテストを入れて、それは私のために働くように見えました。 –
確かに.. treeView.Items.Clear()を呼び出すと、何も起こりません。私はまた、単語の後にtreeView.Items.UpdateLayout()を試みました...まだ何もありません。それは簡単です。 – wakurth