We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Center floating window according to main window

Hi,

I have a WPF application that has a DockingManager. It also contains a button that adds floating windows. But those windows, when created, always pop up in the upper left corner of the main screen. Instead, I'd like them to pop up in the center according to the main application. I noticed the property FloatingWindowRect but I can't use it because I'd have to hard code some values and it seems that the floating window will always pop up in the main screen (consider the fact that the user might have more than one screen).

How can I tell the floating window to pop up in the center according to its main application window?

Thanks for your help

3 Replies

TA Thirumurugan Arumugam Syncfusion Team March 23, 2015 02:44 PM UTC

Hi Guillaume,

Thank you for contacting Syncfusion support.

Currently we can only set the position of FloatWindow by SetFloatingWindowRect() method of DockingManager. We have created a class named WindowPosition to return the center position of the Window by invoke the Method GetWindowCenterPoint(). We have prepared a sample that tries to meet your requirement. In this sample we have created the FloatWindow at center point by SetFloatingWindowRect() with center position of Window. We have attached the sample and you can download the sample from the following location.

Sample link: DockingManagerSample.zip

Please let us know if you need any further assistance,

Regards,

Thirumurugan Arumugam.



AN anthony nichols September 1, 2015 08:01 PM UTC

I was unable to get the example to work. I am using MVVM so maybe that is why. This is the solution I was able to get to work in Code Behind. This is called right after initialization.
double width = 200;
double height = 300;
 
var bounds = Application.Current.Windows[0].RestoreBounds;
if (bounds != null)
{
    // Set the position to the center
    DockingManager.SetFloatingWindowRect(this,
        new Rect(
            bounds.Left + (bounds.Width / 2) - (width / 2),
            bounds.Top + (bounds.Height / 2) - (height / 2),
            width, height)
        );
}


VR Vijayalakshmi Roopkumar Syncfusion Team September 2, 2015 10:48 AM UTC

Hi Anthony,

We have prepared a simple sample that tries to meet your requirement. The solution you have used will work even in MVVM sample, but we must set the code for setting the float window at center in the child loaded event. In our sample, we have set the usercontrol as a child for DockingManager and set it in the center position of its loaded event. The same has been demonstrated in the following sample:

Sample:DockingManager_118596

Please try our sample and let us know if it helps you.

Regards,
Vijayalakshmi V.R.

Loader.
Live Chat Icon For mobile
Up arrow icon