I have managed to create an example project that uses HwndHost to host Notepad (not what my real project will be embedding) inside a C# WPF tab control. For this, many thanks goes to those who replied to Hosting external app in WPF window (BTW there's no need for DwayneNeed)
This example works beautifully until you click on the hosted instance of Notepad, and then try to change tabs. If you don't have any content in the new page you are navigating to, you have to click on your current page selector first before it will accept a click on the other tab. If you have content on the other page (anything... just a button), then you are forced to click on the new tab selector TWICE to get it to navigate away.
Things I have tried that didn't work:
- Using AttachThreadInput() to join the input threads of both application windows.
- Calling
this.InvalidateVisual();
on the Tab Control mouse down event.
What does the trick:
- Programmatically changing the
TabControl.SelectedIndex
value to what I want when a button is pressed.
To get around this problem, I think I am just going to have to use buttons in the place of the Tab Selectors (making them invisible) and just change the pages programmatically. This isn't a big deal, but I would just like to know if anyone else has encountered this problem, and maybe has an explanation for it!
p.s. I'm kinda new to WPF and C#.