Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the contents of a canvas in wpf?

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.

Any help is greatly appreciated

like image 511
lata Avatar asked Dec 10 '22 19:12

lata


1 Answers

You want to do 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();
}
like image 135
Kory Gill Avatar answered Dec 13 '22 11:12

Kory Gill