How to use a dialog in an Excel shared folder
I am writing a generic Excel addon. It adds a CommandBarButton that, when clicked, opens a WPF window to collect some information from the user.
I wanted to keep the same WPF dialog in memory and reuse it so that if the user hits the CommandBarButton again, their old values will still be there.
So, I made a link to my WPF dialog as a private member of my addin object that implements Extensibility.IDTExtensibility2.
I created the window during OnStartupComplete (), but for some reason, when I start Excel, the window opens immediately, although I never called ShowDialog (), and when I call ShowDialog (), when CommandBarButton is pressed to reopen the window. is not downloading.
Does anyone know why this is happening and what is the correct way to handle it?
Thanks a lot for any help.
UPDATE CODE:
public void OnStartupComplete(ref System.Array custom)
{
MyDialog dlg = new MyDlg(); //This will open the dialog ?!?!
}
....
public MyDialog()
{
InitializeComponent();
Loaded += new RoutedEventHandler(OnLoaded);
}
OnLoaded just hooks up some event handlers for the buttons and sets up some ItemSources. Even if I comment it, it will still open the window.
I figured out that when the WPF window is closed it cannot be canceled and that is by design. But why it opens automatically when it is embedded in the excel addin is a mystery.
a source to share