How can I center RadWindow?

4 posts, 0 answers
  1. Alan
    Alan avatar
    2 posts
    Member since:
    Sep 2012

    Posted 13 Aug 2010 Link to this post

    Good morning, afternoon, evening,

    I am having trouble figuring out how I can center a RadWindow using WindowStartupLocation.CenterOwner when I open it from a non-wpf application.

    I used the following code in my winform app to open a dialog that is a System.Windows.Window.  When I convert it to a RadWindow, it doesn't work and I am at a loss as to how to duplicate functionality.

     

     

     

    var dlg = new MyDialog();

     

    System.Windows.Interop.

     

    WindowInteropHelper hwndHelper = new System.Windows.Interop.WindowInteropHelper(dlg);

     

    hwndHelper.Owner =

     

    new IntPtr(Globals.ThisAddIn.Application.Hwnd);

     

    dlg.ShowDialog();

    How can I center the window?

    Please assist.

    Thanks,
    Alan

    PS.  I have a support agreement but decided to post here so that others might benefit from response.

  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 18 Aug 2010 Link to this post

    Hi Alan,

    Thank you for contacting us.

    To center the RadWindow you can hook to the Loaded event of the MainWindow and set the WindowStartupLocation property there, for example:

    private void Window_Loaded(object sender, RoutedEventArgs e)
         {
             window = new MyWindow();
             window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
             window.Owner = this;
             window.Show();
         }


    Hope this helps. If you need further help please let us know.

    Sincerely yours,
    Konstantina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alan
    Alan avatar
    2 posts
    Member since:
    Sep 2012

    Posted 19 Aug 2010 Link to this post

    Good morning/afternoon/evening Konstantina,

    Unfortunately, my question is how to do this from a non-WPF application ie I am opening the RadWindow from a winforms app.  The suggestion that you provided only works if you are opening a RadWindow from another wpf window.

    Any other suggestions are welcome?

    Thanks,
    Alan
  5. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 23 Aug 2010 Link to this post

    Hi Alan,

    Thank you for your reply.

    I can suggest you to center RadWindow manually according left, top, width, height properties of the Owner. 
    Here is how you could accomplish this:

    // Manually calculate Top/Left to appear centered 
    RadWindow control = new RadWindow() { Width = 200, Height = 100 };
       
    int nonWPFOwnerLeft = ...; // Get non-WPF owner’s Left
    int nonWPFOwnerWidth = ...; // Get non-WPF owner’s Width
    int nonWPFOwnerTop = ...; // Get non-WPF owner’s Top
    int nonWPFOwnerHeight = ...; // Get non-WPF owner’s Height
    control.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
    control.Left = nonWPFOwnerLeft + (nonWPFOwnerWidth - control.Width) / 2;
    control.Top = nonWPFOwnerTop + (nonWPFOwnerHeight - control.Height) / 2;
       
    // Show the owned WPF window
    control.Show();

    This code is from official Microsoft blog Centering WPF Windows with WPF and Non-WPF Owner Windows

    Hope this is helpful. If you have any other questions about our controls please let us know.

    Greetings,
    Konstantina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top