Tuesday, July 13, 2010

DXWindow and DXDialog as Silverlight a UserControl

Here is a quick example of making a DXDialog or DXWindow a user control in your Silverlight applications.

Add a reference to DevExpress.xpf.Core to you Silverlight application.

Modify the xaml so that it is a DXWindow (or DXDialog).

<dec:DXDialog x:Class="DevExpressWindow.Dialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:dec="clr-namespace:DevExpress.Xpf.Core;assembly=DevExpress.Xpf.Core.v10.1"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">    
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="Your UI here." HorizontalAlignment="Center" VerticalAlignment="Center"/>

    </Grid>
</dec:DXDialog>


 


 

And modify the code behind so that instead of deriving from UserControl, derive from DXwindow (or DXDialog) like so.

using System;
using DevExpress.Xpf.Core;


namespace DevExpressWindow
{
    public partial class Dialog : DXDialog
    {
        public Dialog()
        {
            InitializeComponent();
        }
    }
}


 

And to use it from within the application

  private void btnNewDialog_Click(object sender, RoutedEventArgs e)
  {
            Dialog dlg = new Dialog { Title = "My Dialog",Height=200 };
            dlg.ShowDialog();
  }


 

The result is a reusable dialog or window.