Use RadWindow as User Control

If you want to prepare the RadWindow at design-time, you have to use it as a user control. To do this you have to create a standard user control using the UserControl template in the Visual Studio. This example will use a UserControl called "RadWindowControl".

After creating it open the XAML file and replace the UserControl 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" 
   telerik:StyleManager.Theme="Vista" 
   xmlns:local="clr-namespace:RadWindowSamples.How_To"> 
</telerik:RadWindow> 
Also in the code behind your user control should inherit the RadWindow instead of the UserControl.

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 Silverlight, 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. 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:RadWindowControl" BasedOn="{StaticResource RadWindowStyle}" /> 
    </ResourceDictionary> 
</Application.Resources> 
The important part is setting TargetType property to the type of the user control.
In this article
Not finding the help you need? Improve this article