Show a WPF window in the center of the AutoCAD window

Show a WPF window in the center of the AutoCAD window

Anonymous
Not applicable
3,297 Views
1 Reply
Message 1 of 2

Show a WPF window in the center of the AutoCAD window

Anonymous
Not applicable

Hello everyone,

 

How can I show a WPF window in the center of the main AutoCAD window?

I set a property WindowStartupLocation of my window  to CenterOwner. But how can I set the main AutoCAD window as an owner of the window (there is an Owner property, but its type is System.Windows.Window)?

 

Thank you!

0 Likes
Accepted solutions (1)
3,298 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

How do you show the window (with your code)? Does the window show as Modal, or as Modeless?

 

Whether you use Win Form or WPF, DO NOT use Form/Window.Show()/ShowDialog() to show the form/window in AutoCAD. Use AutoCAD .NET API's ShowModal[Modeless]Dialog[Window]() method, which has various overloads, where you can pass AutoCAD window's handle as your form/window's owner; you can also pass a parameter to let AutoCAD to remember the form/windows previous location.

 

So it would be as simple as:

            var dialog = new MyWpfWindow();
            Application.ShowModalWindow(Application.MainWindow.Handle, dialog, false);
            dialog.Close();

In this code, the Window's startup location is set to OwnerCenter. and the last parameter passed on ShowModalWindow() is false, meaning AutoCAD does not remember the previous location (thus does not try to place the form/window is previous location).

Norman Yuan

Drive CAD With Code

EESignature