在WPF中删除Wrap面板

时间:2014-06-04 14:31:58

标签: c# wpf

我尝试从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);
                }

1 个答案:

答案 0 :(得分:3)

尝试与我合作的代码:

的Xaml

<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);