This is a migrated thread and some comments may be shown as answers.

RadContextMenu on RadMenuItem

2 Answers 318 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 14 Dec 2015, 05:17 PM

Hi, 

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> 

Styles:

 <UserControl.Resources>
            <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}"/>                              
        </Style>           
    </UserControl.Resources>

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 >
                            <DataTemplate>
                                     <telerik:RadMenuItem Header="{Binding}" ContextMenuOpening="RadMenuItem_ContextMenuOpening" >
                                              <telerik:RadContextMenu.ContextMenu>
                                                <telerik:RadContextMenu>                                                
                                                    <telerik:RadMenuItem Header="{Binding }"/>
                                                </telerik:RadContextMenu>
                                            </telerik:RadContextMenu.ContextMenu>                            
                                    </telerik:RadMenuItem>   
                            </DataTemplate>
                 </telerik:RadMenu.ItemTemplate>-->
            </telerik:RadMenu>

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 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 17 Dec 2015, 11:13 AM
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.

Regards,
Nasko
Telerik
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
0
Carlos
Top achievements
Rank 1
answered on 22 Dec 2015, 10:35 AM

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

 Regards.

Tags
ContextMenu
Asked by
Carlos
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Carlos
Top achievements
Rank 1
Share this question
or