Search code examples
outlookvstooutlook-addinoffice-addinscustomtaskpane

VSTO Outlook: Embed an WPF user control within a form region


Currently I have an WPF user control embedded within an Outlook custom task pane. The problem with the task pane is that you cannot remove the title bar so I was thinking about using a form region instead and reusing the existing WPF user control I already have. So, is it possible to embed an WPF user control within a form region? If so how.


Solution

  • You cannot add WPF controls directly to UI elements in Office solutions. Instead, add a User Control (WPF) item to your project, and use it as the design surface for WPF controls. Then, add the WPF user control to a UI element in your project. Visual Studio automatically creates an ElementHost object that hosts the WPF user control on the UI element. Or just add the ElementHost control to the user control and then configure it to host your WPF control.

    Read more about that in the Use WPF controls in Office solutions article.