Search code examples
c#wpfrevit-apirevit

Is this a way to show a modeless dialog from a dockable pane using WPF?


I'm building a Revit plugin. It consists of a dockable pane that (among other elements) has a button. I want to open a new, separate window when a user clicks this button.

At the moment, i create a new Window, but i don't know if that's the right way to go, because now i see two Revit icons on a task bar. I do not have experience as Revit user, i'm new to Revit development, so i'm not sure if this should be the case (two icons) and as silly as it sounds, i do not have admin rights to install random addins and get a feeling of expected user experience.

enter image description here

I create a Window using the following code:

ParametersMissingValueWindow parametersMissingValueWindow = new ParametersMissingValueWindow();
parametersMissingValueWindow.Show();

Based on the understanding of a dockable pane that i have, i think i do not want to create another dockable pane, but just a simple modeless dialog. I wasn't able to find any examples using WPF. Hence, any information whether this is the way to go or help on how to achieve this is highly appreciated.


Solution

  • var MyWindow = new MyWindow();
    HwndSource hwndSource = HwndSource.FromHwnd(UIApplication.MainWindowHandle);
    Window wnd = hwndSource.RootVisual as Window;
    if (wnd != null)
    {
        MyWindow.Owner = wnd;
        //MyWindow.ShowInTaskbar = false;
        MyWindow.Show();
    }
    

    It's not necessary to assign a value to ShowInTaskbar property, but it actually achieves what i wanted to do from the beginning (have only one program open in taskbar), so i left it as part of the solution, but commentted out.

    Big thanks to Jeremy Tammik for pointing out the parent property.