We are using some ActiveX or windows form control which don't have the WPF equivalences, so naturally we use WindowsFormsHost to host these controls. We normally make an UserControl out of it with some general controls such as button to implement the common functionality. One piece of xaml code is something like this:
<WindowsFormsHost Name="windowsFormsHost1" >
<WindowsFormsHost.ContextMenu>
<ContextMenu>
<MenuItem Header="_Test1" />
</ContextMenu>
</WindowsFormsHost.ContextMenu>
<AxOWC:AxPivotTable x:Name="pivotTable" />
</WindowsFormsHost>
....
The AxPivotTable is a OWC (office web component) control. In another UserControl, we add a ReportViewer inside the WindowsFormsHost. Note that normally the AxPivotTable or ReportViewer has its default context menu even without any ContextMenu item I add.
So far my customized ContextMenu doesn't get showed yet (still the default one shows). Thanks to this question, I figured out I still need to capture the the mouse down event in the code-behind and set
windowsFormsHost1.ContextMenu.IsOpen = True
to show the contextmenu (weird though).
Now my problem is, only this Test1 ContextMenu is here now. The default ContextMenu won't show any more. As I mentioned, what we want is to add the customized on top of those default context menus.
windowsFormsHost1
to get theContextMenu
object? so you could do_yourContextMenu_.Items.Add(newMenuItem)
- WiiMaxx