Close current UserControl

BlueMan picture BlueMan · Jun 1, 2010 · Viewed 32.7k times · Source

I have a Window1.xaml main Window; and after some event, I display a UserControl EditFile.xaml.

The code behind is:

public static int whichSelected = -1;
private void button1_Click(object sender, RoutedEventArgs e)
{
    //searchEditPanel.Children.Clear();
    whichSelected = listViewFiles.SelectedIndex;
    searchEditPanel.Children.Add(_EditFileControle);        //this is Grid
}

And now, how can I close the opened/added UserControl from its content by clicking a Cancel button or something like that?

Answer

Dino MARIANO picture Dino MARIANO · Jul 3, 2014
Window.GetWindow(this).Close();

You don't need to use a new variable, you can use it directly.