This is a migrated thread and some comments may be shown as answers.

How can I center RadWindow?

3 Answers 564 Views
Window
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 13 Aug 2010, 09:04 PM

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.

3 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 18 Aug 2010, 08:23 AM
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
0
Alan
Top achievements
Rank 1
answered on 19 Aug 2010, 04:08 PM
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
0
Konstantina
Telerik team
answered on 23 Aug 2010, 08:13 AM
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
Tags
Window
Asked by
Alan
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Alan
Top achievements
Rank 1
Share this question
or