wpf 如何清除wpf中画布的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34403009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear the contents of a canvas in wpf?
提问by lata
How to clear the contents of a canvas in wpf? Tried canvas.clear() doesn't work. Also how can i add zoom control in a wpf application? Zoom with a scroller to move the image.
如何清除wpf中画布的内容?试过 canvas.clear() 不起作用。另外如何在 wpf 应用程序中添加缩放控件?使用滚动条缩放以移动图像。
Any help is greatly appreciated
任何帮助是极大的赞赏
回答by Kory Gill
You want to do MyCanvas.Children.Clear();
你想做 MyCanvas.Children.Clear();
Tested with the following code:
使用以下代码进行测试:
<Grid>
<Canvas Name="MyCanvas"/>
<Button Click="Button_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="200" Content="Clear"/>
</Grid>
and
和
public MainWindow()
{
InitializeComponent();
MyCanvas.Children.Add(new TextBlock() { Text = "Foo" });
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MyCanvas.Children.Clear();
}

