Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
XamContextMenu for WindowsFormsHost
posted

Hi,

On a WPF UserControl, I'm having a WindowsFormsHost. And I'm using a Win forms control as a child for it. I have 2 requirements here:

1. I would like to display the XamContextMenu, whenever the user right-clicks on the child control of the WindowsFormsHost.

2. I have another win forms control, which I want to use as a sub menu in the XamContextMenu.

Here is the code I used:

 <Grid>

 <WindowsFormsHost Name="ViewHost" Background="Transparent">

 </WindowsFormsHost>

 <ig:ContextMenuService.Manager>

 <ig:ContextMenuManager>

 <ig:ContextMenuManager.ContextMenu>

 <ig:XamContextMenu ItemClicked="XamContextMenu_ItemClicked" ContextMenuOpening="XamContextMenu_ContextMenuOpening" Name="mnuContextMenu">

 <ig:XamMenuItem Header="Items" Name="mnumnuItems">

 <ig:XamMenuItem Header="New Item" Name="mnuNewItem"/>

 <ig:XamMenuItem Header="Edit" Name="mnuEditItem"/>

 <ig:XamMenuItem Header="Remove" Name="mnuRemoveItem"/>

 </ig:XamMenuItem>

 <ig:XamMenuItem Header="Configure" Name="mnuConfigure">

 <ig:XamMenuItem Name="mnuTimeEntry">

 <ig:XamMenuItem.Template>

 <ControlTemplate>

 <WindowsFormsHost>

 <local:TimeEntryControl/>

 </WindowsFormsHost>

</ControlTemplate>

</ig:XamMenuItem.Template>

</ig:XamMenuItem>

</ig:XamMenuItem>

</ig:ContextMenuManager.ContextMenu>

 

 

 

</ig:ContextMenuManager>

 

 

 

</ig:ContextMenuService.Manager>

 

 

</Grid>

 

 

 

NOTE:

 

Child property of the WindowsFormsHost  (ViewHost) will be set dynamically in code.

<local:TimeEntryControl/> is the win forms user control to be used as the sub menu.

But this is not working. ContextMenu is not coming up when the user right clicks. XamContextMenu comes up if we use some other control (like button etc.,), except for the WindowsFormsHost.

In that case also TimeEntryControl is not showing up as a sub menu. Only a blank menu comes up Earlier this was really simple in Win forms with the use of  PopupControlContainerTool and UltraToolbarsManager.

Please help me on how this can be implemented. [I'm not sure why the preview inserts a lot of space into this post.]

Regards,

Sugan Raj

  • 138253
    Offline posted

    Hello,

     

    It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post and I can say the XamCotextMenu can be used with controls that derives from DependancyObject class and the UserControl class that WindowsForms’ UserControl derives from doesn’t derive it. I can suggest you set the ContextMenu in the UserControl directly.

     

    Feel free to write me if you have further questions.