.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WPF - MVVM : prevent multiple calls of Dialogs

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
melomayo6BC8R
238 Views, 2 Replies

WPF - MVVM : prevent multiple calls of Dialogs

How can I prevent a modeless dialog created as WPF from being called again until it has been closed?

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: melomayo6BC8R

Using modeless dialog/window/PalleteSet is tricky.

Typically, it should be instantiated as singleton object in an AutoCAD session, something like:

 

public class MyCommandClass

{

   private static MyWindow _window=null

   [CommandMethod("ShowMyWindow", CommandFlags.Session)]

   publci static void ShowMyWindow()

   {

      If (_window==null)

      {

         _window=new MyWindow();

      }

      Application.ShowModelessWindow(_window);

   }

}

 

In this case, you would want to handle Window.Closing event, where you cancel the closing and set its Visibility property to Hidden.

 

That is, one the window is instantiated, it stays in the AutoCAD session, being either hidden or visible. 

Obviously, id the content of the window is drawing specific, you need to reset the content whenever current drawing changes.

 

You can also instantiate the modeless window on "per-document" basis (you could take advantage of [PerDocumentClass]. 

 

These old articles might be of help:

https://drive-cad-with-code.blogspot.com/2014/02/showing-and-closing-modeless-formdialog.html 

https://drive-cad-with-code.blogspot.com/2018/09/showing-modeless-form-with-help-of.html 

 

Since you use MVVM pattern, you can let the ViewModel to subcribe DocumentBecameCurrent event and update the ViewModel, which in turn update the window view.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

Hi Norman,
many heartfelt thanks for that. Duplicate dialog calls are prevented by a static variable.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report