RadContextMenu on RadMenuItem

3 posts, 0 answers
  1. Carlos
    Carlos avatar
    2 posts
    Member since:
    Jul 2013

    Posted 14 Dec 2015 Link to this post


    We are using RadMenu on a  solution with wpf and telerik on this way:

    Here is the element menu: 

     <telerik:RadMenu x:Name="MenuPrincipal" ItemsSource="{Binding MenuItems}"                         
                             ItemContainerStyle="{StaticResource MenuItemStyle}" >  </telerik:RadMenu> 


                <Style x:Key="MenuItemStyle" TargetType="telerik:RadMenuItem">
                    <Setter Property="Command" Value="{Binding Command}" />
                    <Setter Property="CommandParameter" Value="{Binding CommandParameter}" />
                    <Setter Property="Header" Value="{Binding Header}" />
                    <Setter Property="ItemsSource" Value="{Binding Items}"/>
                    <Setter Property="IsSeparator" Value="{Binding IsSeparator}"/>                              

    The item collection are generated like a ObservableCollection of our own class with header, subitems, and everything it´s working fine. The Menu it´s appearing ok on the screen and showing correctly the childs and parents. The relation between parents and childs inside the RadMenu Items are working fine :)

    The problem is... now, i need to add a RadContextMenu on some items of the menu, and i don´t know how to do it. I´m trying to do on several ways, but nothing it´s working properly.

    First try:

     <telerik:RadMenu x:Name="MenuPrincipal" VerticalAlignment="Top"  ItemsSource="{Binding MenuItems}"                         
                             ItemContainerStyle="{StaticResource MenuItemStyle}" >                      
                      <telerik:RadMenu.ItemTemplate >
                                         <telerik:RadMenuItem Header="{Binding}" ContextMenuOpening="RadMenuItem_ContextMenuOpening" >
                                                        <telerik:RadMenuItem Header="{Binding }"/>

    That way, creates the menu item like a button (with a border...) and it´s not responding on click. (If i click outside the border the menu displays). I can Solve with "autoopen", but in that way, when the context menu has showed, the menu closes, also whit "stayopen" property enabled. 


    Second Try

    With codebehind - Trying to add a RadContextMenu on our own class of the menu and binding on  that way <Setter Property="ContextMenu" Value="{Binding ContextMenu}"/> Not succesfull :( 

    Also to consider. I need to show the menu only in the final childs, not in the parent menus... 

    Any help will be appreciated. 

    Thank you, regards. 



  2. Nasko
    Nasko avatar
    559 posts

    Posted 17 Dec 2015 Link to this post

    Hello Carlos,

    What we could suggest in order to achieve the desired functionality and add ContextMenu for only some of the items is to use ItemContainerStyleSelector. Using the selector you could return a Style that contains ContextMenu for those items you want and need and for the one that do not need to have ContextMenu you could return the default Style of the MenuItem.

    We have created a sample project that demonstrates that approach - please, notice how only two of the three children of the first menu item has set ContextMenu.

    Hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Carlos
    Carlos avatar
    2 posts
    Member since:
    Jul 2013

    Posted 22 Dec 2015 in reply to Nasko Link to this post

    Thank you so much Nasko, we have implemented the code on our solution and it´s working fine. 


Back to Top