New to Telerik UI for WPF? Download free 30-day trial

Use RadWindow as Main Window or User Control

If you want to prepare the RadWindow at design-time or use it as the MainWindow of your application, you have to use it as a user control. To do this you cancreate a standard user control or window using the templates provided in the Visual Studio or replace the default MainWindow created for the application.

First open the XAML file and replace the generated declaration with a RadWindow declaration. Here is a sample code:

<telerik:RadWindow x:Class="RadWindowSamples.MainWindow" 
   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"" 
   xmlns:local="clr-namespace:RadWindowSamples"> 
</telerik:RadWindow> 

You need to replace RadWindowSamples with the namespace of the generated class.

Also in the code behind your user control should inherit the RadWindow instead of the UserControl class.

public partial class MainWindow : RadWindow 
{ 
    public MainWindow() 
    { 
        InitializeComponent(); 
    } 
} 
Partial Public Class MainWindow 
    Inherits RadWindow 
    Public Sub New() 
        InitializeComponent() 
    End Sub 
End Class 

If you have installed UI for WPF, you can easily create the RadWindow UserControl with the Telerik templates - just click Add -> New Item... in the project Context Menu and choose "Telerik Scenario" from the installed templates. In the Scenario Wizard select RadWindow.

In the XAML you can declare the content of the RadWindow directly in XAML and use the code-behind to wire-up some logic, as you would do with an UserControl. You can also set the properties of the RadWindow. This way you can have a configured RadWindow at design time and the only thing you have to do is to show it, when needed.

As this is an user control of type RadWindow you can use any of the features that are provided by the RadWindow. So if you want to show it, you have to call the Show() method.

MainWindow window = new MainWindow(); 
window.Show(); 
Dim window As New MainWindow() 
window.Show() 

If you want to use RadWindow as the main window of the application, remove the StartupUri setting in the App.xaml file.

<Application x:Class="RadWindowSamples.App" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
             <!--StartupUri="MainWindow.xaml"--> 
    <Application.Resources> 
 
    </Application.Resources> 
</Application> 

Then create a new instance of the custom RadWindow and show it in the OnStartup method override of the App class.

public partial class App : Application 
{ 
    protected override void OnStartup(StartupEventArgs e) 
    { 
        MainWindow window = new MainWindow(); 
        window.Show(); 
    } 
} 
Public Partial Class App 
    Inherits Application 
    Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs) 
    Dim window As MainWindow = New MainWindow() 
    window.Show() 
    End Sub 
End Class 

If you're using Implicit Styles to style the controls, note that the newly created user control will not receive automatically the Window style. You should add the following style after the merged dictionaries to fix this:

<Application.Resources> 
    <ResourceDictionary> 
        <ResourceDictionary.MergedDictionaries> 
            <ResourceDictionary Source="Themes/System.Windows.xaml" /> 
            <ResourceDictionary Source="Themes/Telerik.Windows.Controls.xaml" /> 
            <ResourceDictionary Source="Themes/Telerik.Windows.Controls.Navigation.xaml" /> 
        </ResourceDictionary.MergedDictionaries> 
        <Style TargetType="local:MainWindow" BasedOn="{StaticResource RadWindowStyle}" /> 
    </ResourceDictionary> 
</Application.Resources> 

The important part is setting TargetType property to the type of the user control.

In addition, due to a change in the XAML Designer in Visual Studio version 16.9 (and newer), if the RadWindow is used as Main Window or UserControl, it will not be displayed in design time. To display it, you need to apply the following explicit style:

<telerik:RadWindow (namespaces omitted) ... Style="{StaticResource RadWindowStyle}"/> 
In this article