首先是我想要做的事情:我需要动态反转一个堆栈面板中项目的顺序,并在一秒钟内以相反的顺序添加它们。这是我正在使用的代码:
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
它很好地运行了这段代码,但在加载用户控件之前我收到了错误。我在这里环顾四周,似乎可行的解决方案是将孩子从我已经做的第一个集合中删除。任何帮助,将不胜感激。谢谢