Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How can I prevent a modeless dialog created as WPF from being called again until it has been closed?
Solved! Go to Solution.
How can I prevent a modeless dialog created as WPF from being called again until it has been closed?
Solved! Go to Solution.
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.
Hi Norman,
many heartfelt thanks for that. Duplicate dialog calls are prevented by a static variable.