我尝试从c#代码中删除Wrap Panel。 Wrap面板位于Canvas内。代码段如下
this.CanvasName.Children.Remove(WrapPanelName);
然而,Wrap Panel仍然出现在Window中?任何帮助!
编辑: 此代码有效,
int childCount = WrapPanelName.Children.Count;
for (int i = 0; i < childCount; i++)
{
///Remove the old.
WrapPanelName.Children.RemoveAt(0);
}
答案 0 :(得分:3)
尝试与我合作的代码:
<Canvas Name="YourCanavasName">
<WrapPanel Name="YourWrapName" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Rectangle Canvas.Left="40" Canvas.Top="31" Width="63" Height="41" Fill="Blue" />
<Ellipse Canvas.Left="130" Canvas.Top="79" Width="58" Height="58" Fill="Blue" />
</WrapPanel>
</Canvas>
YourCanavasName.Children.Remove(YourWrapName);