0
首先,我要做的是:我需要動態地顛倒一個堆棧面板中項目的順序,並在一秒內以相反順序添加它們。這裏是我使用的代碼:指定的元素已經是另一個元素的邏輯子元素。先斷開它。刪除後
Dim cp As ContentPresenter = TryCast(Utilities.GetDescendantFromName(TitleLegend, "ContentPresenter"), ContentPresenter)
If cp IsNot Nothing Then
Dim sp As StackPanel = TryCast(cp.Content, StackPanel)
If sp IsNot Nothing Then
Dim nsp As New StackPanel() With {.Orientation = System.Windows.Controls.Orientation.Vertical}
Dim count As Integer = sp.Children.Count
For i As Integer = count - 1 To 0 Step -1
Dim cc As ContentControl = TryCast(sp.Children(i), ContentControl)
If cc IsNot Nothing Then
sp.Children.Remove(cc)
nsp.Children.Add(cc)
End If
Next
cp.Content = Nothing
cp.Content = nsp
End If
End If
它運行通過此代碼很好,但就在用戶控制加載之前我收到錯誤。我在這裏環顧四周,似乎工作的解決方案是從我已經做的第一個集合中刪除孩子。任何幫助,將不勝感激。謝謝