# Close the RadWindow Through its Content

To close the **RadWindow** through its content you have to get the instance of the **RadWindow** and call its **Close()** method. This tutorial will handle two possible scenarios:

* [When the content is directly set to the RadWindow](https://www.telerik.com/products/wpf/documentation/controls/radwindow/how-to/close-the-radwidnow-through-its-content#content-directly-set-to-the-radwindow)

* [When the content is represented by a UserControl](https://www.telerik.com/products/wpf/documentation/controls/radwindow/how-to/close-the-radwidnow-through-its-content#content-represented-by-a-usercontrol)

## Content, directly set to the RadWindow

> tip To learn more about how to use the **RadWindow** as user control read [this topic](https://www.telerik.com/products/wpf/documentation/controls/radwindow/how-to/use-radwindow-as-user-control).

Here is a sample **RadWindow**, used as user control, with a button in it:

```XAML
<telerik:RadWindow x:Class="RadWindowSamples.RadWindowControl2"
	                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	                   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Close me!" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
</telerik:RadWindow>
```

As the button is in the same control like the **RadWindow**, you can get the **RadWindow** instance in the code-behind. In order to close the window through the button you have to attach to its **Click** event and call the **Close()** method of the **RadWindow**.

```XAML
<Button Content="Close me!"
	        Click="Button_Click"
	        HorizontalAlignment="Center"
	        VerticalAlignment="Center" />
```

```C#
private void Button_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}
```

```VB.NET
	Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
	    Me.Close()
	End Sub
```

> tip Instead of event handler you can use a **RadButton** with the **Close** command for the **RadWindow**. Here is an example:

```XAML
<telerik:RadButton Content="Close me!"
	                   HorizontalAlignment="Center"
	                   VerticalAlignment="Center"
	                   Command="telerik:WindowCommands.Close" />
```

## Content, represented by a UserControl

In this scenario the **Button** is placed inside a **UserControl**, which is passed as the **Content** of the **RadWindow**. In this case you cannot access the **RadWindow** directly from the **UserControl** as it is not aware of its existance. In order to close the **RadWindow** when the button is clicked, you have to use the **ParentOfType\<T>()** extension method to get the **RadWindow** instance.

> tip The **ParentOfType\<T>()** is available when you use the **Telerik.Windows.Controls** namespace from the **Telerik.Windows.Controls**. It returns the first element of this type up in the **Visual Tree**.

```C#
private void Button_Click(object sender, RoutedEventArgs e)
{
    RadWindow window = this.ParentOfType<RadWindow>();
    window.Close();
}
```

```VB.NET
	Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
	    Dim window As RadWindow = Me.ParentOfType(Of RadWindow)()
	    window.Close()
	End Sub
```

## See Also

* [Working with RadWindow](https://www.telerik.com/products/wpf/documentation/controls/radwindow/features/working-with-radwindow)

* [Use Keyboard to Get User Response](https://www.telerik.com/products/wpf/documentation/controls/radwindow/how-to/use-keyboard-to-get-user-response)

* [Prevent Dragging Off the Screen](https://www.telerik.com/products/wpf/documentation/controls/radwindow/how-to/prevent-dragging-off-the-screen)
