none
Handle window modal dialog open with word document RRS feed

  • Question

  • I have a Word Addin project which is having a custom ribbon developed using ribbon-customUI. In that, I have a dynamic menu which gets the contents from GetContent() function from code behind file.

    Ribbon.xml

    <dynamicMenu id="buttonMenu" getImage="GetImage" getContent="GetContent" invalidateContentOnDrop="true" label="Menu Button" size="large"></dynamicMenu>

    Ribbon.cs - (This method will be having dynamic button controls latter)

    public string GetContent(IRibbonControl control) {                       
    StringBuilder CustomSB = new StringBuilder(@"<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >");            
    CustomSB.Append(@"<button id=""button1"" label=""Sample Create"" onAction=""SampleCreateClick"" />");            
    CustomSB.Append(@"</menu>");            
    return CustomSB.ToString();    
    }

    When clicking the button, the SampleCreateClick() function will be called. It will need to open a new WPF window (NewFormDialog)

    public void SampleCreateClick(IRibbonControl control) {            
      var dialog = new NewFormDialog();            
      var options = new MyViewModel();
      dialog.DataContext = options;
      ShowModalDialog(dialog, (Window)control.Context);      
    }

    The ShowModalDialog() method will handle the new window popup opens and forced to open the word document.

    private void ShowModalDialog(System.Windows.Window dialog, Window win) 
    {            
      var wih = new WindowInteropHelper(dialog);   
      wih.Owner = Win32.DocumentWnd.GetDocWindowHandle(win);   
      dialog.ShowDialog();        
    }

    But my problem is that this ShowModalDialog() method is working fine (Open the form window with word document itself, not separately) with other controls(ex:- normal ribbon button controls) but not work (Can open document and window separately) when it is called inside a dynamic menu control.

    Can you have a solution on this?




    • Edited by KameshIndika Tuesday, September 6, 2016 12:17 PM
    Tuesday, September 6, 2016 12:08 PM

All replies

  • Hello,

    Looks like you need to use the Show method instead of the ShowDialog one. See Displaying Modal and Modeless Windows Forms for more information.


    [custom.development]

    Tuesday, September 6, 2016 12:33 PM
  • Show() method is not giving the feature of modal dialog. Can you have another way around?
    • Edited by KameshIndika Thursday, September 8, 2016 6:11 AM
    Thursday, September 8, 2016 6:11 AM
  • There is no way to provide access to the ribbon while the form is displayed. You need to descide whether you want to be shown modally or give users access to the ribbon buttons.

    [custom.development]

    Thursday, September 8, 2016 4:53 PM
  • Hi,

    To my knowledge, we could add WPF controls to VSTO project instead of WPF windows. See Using WPF Controls in Office Solutions

    How do you append the WPF windows? And what do you mean "(Can open document and window separately)"?

    Could you please share more detail information or steps with us, so that we could reproduce your issue.

    Monday, September 12, 2016 7:20 AM
    Moderator
  • It is working fine if I add a Thread.sleep(500) into below code snippet.

    private void ShowModalDialog(System.Windows.Window dialog, Window win) {            var wih = new WindowInteropHelper(dialog);

    Thread.sleep(500)      wih.Owner = Win32.DocumentWnd.GetDocWindowHandle(win);      dialog.ShowDialog();        }

    Can I do this in a better way without having sleep()?

    Monday, September 12, 2016 11:18 AM
  • Since your issues is complicated, I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

     

    Sorry for any inconvenience and have a nice day! 

    Regards,

    Celeste

    Tuesday, September 13, 2016 7:28 AM
    Moderator