MVVM utilizing RadWindow for your popups

Thread is closed for posting
1 posts, 0 answers
  1. k f
    k f avatar
    109 posts
    Member since:
    Jun 2006

    Posted 03 Feb 2011 Link to this post


    RadControls version Q3 2010


    .NET version


    Visual Studio version 2010


    programming language C#


    browser support

    all browsers supported by RadControls


    Here is some code for a RadWindowController I came up and use in my LOB applications.  Keep in mind your needs will vary and feel free to modify this code as needed.

    // Code written by Kris Frost
      void CloseRadWindow();
      void ShowRadWindow(UserControl content, string headerText);
      void ShowRadWindow(UserControl content, bool isRestricted, ResizeMode resizeMode, Telerik.Windows.Controls.WindowStartupLocation windowStartUpLocation,
      string headerText);
      eventEventHandler MainRadWindowClosed;
    publicclassRadWindowController : IRadWindowController
     RadWindow _radWindow;
     // Used so we can alert any consumer when the MainRadWindow has closed.
     publiceventEventHandler MainRadWindowClosed;
     public RadWindowController()
       _radWindow = newRadWindow(); 
       _radWindow.Closed += newEventHandler<WindowClosedEventArgs>(RadWindow_Closed);
     // Call if you need to add your own command to close a popup window
     publicvoid CloseRadWindow()
     public void ShowRadWindow(UserControl content, string headerText)
     // There should only ever be one rad window open using this controller
      // The controller is set to Modal so a user should not be able to open
      // More than these at once anyway. If other options are needed. Create a new RadWindow in code.
      if (_radWindow.IsOpen)
      // We have to wire up to the Current Host's content here so the Rad Window stays centered when the browswer is resized
       Application.Current.Host.Content.Resized += newEventHandler(Content_Resized);
       _radWindow.Content = content;
       _radWindow.Header = headerText;
      // Shows the view passed in a popup window
      publicvoid ShowRadWindow(UserControl content, bool isRestricted, ResizeMode resizeMode,    Telerik.Windows.Controls.WindowStartupLocation windowStartUpLocation,
      string headerText)
        ShowRadWindow(content, headerText);
      #region Private Methods
      void Content_Resized(object sender, EventArgs e)
        _radWindow.Left = (Application.Current.RootVisual.RenderSize.Width / 2 - (_radWindow.ActualWidth / 2));
        _radWindow.Top = Application.Current.RootVisual.RenderSize.Height / 2 - _radWindow.ActualHeight / 2;
      void RadWindow_Closed(object sender, WindowClosedEventArgs e)
      {// Set our window back to default values
    // Unregister when the Window is closed.
    Application.Current.Host.Content.Resized -= newEventHandler(Content_Resized);
    // Remove whatever is assigned to the content when the window is closed.
    _radWindow.Content = null;
    if(MainRadWindowClosed != null)
    MainRadWindowClosed(this, null);
    void SetDefaultWindowValues()
    // Set Default window values to use if a caller doesn't need custom
    _radWindow.IsRestricted = false;
    _radWindow.ResizeMode = ResizeMode.NoResize;
    _radWindow.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;

    For a detailed scenario of how I use this a link to a fully working sample, you can find a write up here.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.