Edit this page

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.RadWindowControl"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&#13;   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&#13;   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"&#13;   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 RadWindowControl : RadWindow
{
    public RadWindowControl()
    {
        InitializeComponent();
    }
}
Partial Public Class RadWindowControl
    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.

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

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.
Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy