0
是否可以刪除一個項目TextBlock
從StackPanel
並將其添加到其他StackPanel
?從StackPanel中刪除一個元素並將其添加到其他StackPanel中
我的XAML代碼如下所示:
<StackPanel x:Name="PanelStack1" VerticalAlignment="Bottom" Margin="0,0,0,86">
<Rectangle x:Name="RecX" />
</StackPanel>
<StackPanel x:Name="PanelStack2" VerticalAlignment="Bottom" Margin="0,0,0,86" />
我想通過我的C#代碼移動從PanelStack1
到PanelStack2
的RecX
。這可能嗎?
這只是一個小例子,在我的真實代碼中有很多元素必須被移動。
這個效果很好,非常感謝你 – gurehbgui 2013-05-12 17:43:41
如果你這樣做的背後程序的代碼,你的應用程序將在一定的情況下崩潰:如果您在搶你的應用程序(例如嘗試進入填充/捕捉模式)並放開它(只需抓住並放開它,再次以全屏方式再次移動),它會崩潰並告訴您RecX已存在於Visual Tree中,並且可以'再次添加。解決方法可以是這樣的:if(!PanelStack2.Children.Contains(RecX))PanelStack2.Children.Add(RecX); – VasileF 2013-05-12 19:18:54