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

ContextMenu works perfectly, but only through mouse use?

10 Answers 303 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 04 Apr 2011, 06:42 AM
Hi Telerik,

I have the xaml below, which gives me a control that responds beautifully to mouse-right-clicks and displays the context menu. The special key on my keyboard for context menu is ignored, however. Any clues as to what I am doing wrong?

Thanks,

Anders, Denmark

<UserControl x:Class="Rap1D.Rap1D_WPF.Controls.Navigator.NavigatorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:WorkspaceExplorer="clr-namespace:Rap1D.ViewModelLayer.Implementations.Commands.WorkspaceExplorer;assembly=Rap1D.ViewModelLayer.Implementations"
             xmlns:TreeViewItems="clr-namespace:Rap1D.ViewModelLayer.Implementations.TreeViewItems;assembly=Rap1D.ViewModelLayer.Implementations"
             xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation">
    <DockPanel>
        <TreeView ItemsSource="{Binding Path=Children, NotifyOnSourceUpdated=True}" Name="treeview">
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="WorkspaceExplorer:MouseDoubleClickBehavior.MouseDoubleClick" Value="{Binding ActivateItemCommand}" />

                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

            <TreeView.Resources>
                <HierarchicalDataTemplate x:Key="MenuItemTemplate"
                                 ItemsSource="{Binding ContextMenuItems}">
                    <TextBlock Text="{Binding Text}" />
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type TreeViewItems:ProjectViewModel}" ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="16" Height="16" Margin="3,0" Source="Images\Project.png" />
                        <TextBlock Text="{Binding DisplayName}" />
                    </StackPanel>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type TreeViewItems:ProductViewModel}" ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="16" Height="16" Margin="3,0" Source="Images\Product.png" />
                        <TextBlock Text="{Binding DisplayName}" />
                    </StackPanel>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type TreeViewItems:ProductDesignViewModel}" ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="16" Height="16" Margin="3,0" Source="Images\ProductDesign.png" />
                        <TextBlock Text="{Binding DisplayName}" />
                    </StackPanel>
                </HierarchicalDataTemplate>

                <DataTemplate DataType="{x:Type TreeViewItems:ProductComponentViewModel}">
                    <StackPanel Orientation="Horizontal">
                        <Image Width="16" Height="16" Margin="3,0" Source="Images\Component.png" />
                        <TextBlock Text="{Binding DisplayName}" />
                    </StackPanel>
                </DataTemplate>
            </TreeView.Resources>
            <Controls:RadContextMenu.ContextMenu>
                <Controls:RadContextMenu x:Name="radContextMenu"
                                         ItemTemplate="{StaticResource MenuItemTemplate}">
                    <Controls:RadMenuItem Header="C_ut"
                                          Command="{Binding CutCommand}" />
                    <Controls:RadMenuItem Header="Copy"
                                          Command="{Binding CopyCommand}" />
                    <Controls:RadMenuItem Header="Paste"
                                          Command="{Binding PasteCommand}" />
                    <Controls:RadMenuItem Header="Delete"
                                          Command="{Binding DeleteCommand}" />
                    <Controls:RadMenuItem Header="_Editor"
                                          Command="{Binding ShowEditorCommand}" />

                </Controls:RadContextMenu>
            </Controls:RadContextMenu.ContextMenu>
        </TreeView>
    </DockPanel>
</UserControl>

10 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 04 Apr 2011, 08:46 AM
Hello Anders,

I was not able to reproduce this issue. If you set ModifierKey on RadContextMenu it will open only when this key is pressed (and the EventName is raised).

You can see it here:
http://demos.telerik.com/wpf/Telerik.Windows.Examples.xbap?ContextMenu/FirstLook

And it works as expected in your xaml.

Could you specify steps so that we can reproduce the behavior where ModifierKey is not working?

All the best,
Hristo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anders
Top achievements
Rank 1
answered on 04 Apr 2011, 09:15 AM
Hi Hristo,

Thank you for quick response!

I think maybe I didn't make my problem clear, but your online example displays my problem perfectly:

1. In either First Look or Integration, left-click on any item to select it.
2. On the keyboard, press the context menu button.

Expected: Contect Menu would appear; same as if right-clicked with the mouse.
Actual: Nothing happends.

(I'm using IE8.0 when viewing you samples).

Anders.
0
Hristo
Telerik team
answered on 05 Apr 2011, 07:42 AM
Hi Anders,

This is the default behavior. RadContextMenu have an EventName property that specify which event to listen to in order to open RadContextMenu and the default value is MouseRightButtonUp.

If you want to use both MouseRightButtonUp and keyboard right click button you could change the EventName to ContextMenuOpening like this:
<telerik:RadContextMenu x:Name="radContextMenu" EventName="ContextMenuOpening">

Let us know if you need more information.

Kind regards,
Hristo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anders
Top achievements
Rank 1
answered on 05 Apr 2011, 04:01 PM
Perfect - I need a little more help though:

When setting the EventName property, it activates perfectly via the keyboard - but now I no longer get the context menu on the mouse right-click event.

I get the RadPane standard context menu(?): Dockable, Floating...

Any suggestions for how to get my own context menu to appear for both events without duplicating the context menu in the xaml?

Thanks,

Anders
0
Hristo
Telerik team
answered on 06 Apr 2011, 10:33 AM
Hi Anders,

We are aware of this issue. It is logged here PITSID.
We will do our best to fix it for the upcoming service pack.
Sorry for the caused inconvenience.

Kind regards,
Hristo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anders
Top achievements
Rank 1
answered on 06 Apr 2011, 10:36 AM
Hi Telerik,

Excellent.

I have a workaround by using two copies of the context menu and look forward to cleaning up my xaml when you release a fix.

Grrrrrrrreetings,

Anders
0
Hristo
Telerik team
answered on 11 Apr 2011, 08:27 AM
Hello Anders,

The fix will be included in the next Latest Internal Build that will be released today or tomorrow so you could give it a try.

Regards,
Hristo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anders
Top achievements
Rank 1
answered on 11 Apr 2011, 08:33 AM
I will (sometime during the week). Thanks for letting me know!
0
Christian
Top achievements
Rank 1
answered on 16 Jan 2012, 09:15 AM
Hi,

In what way was this fixed? Can I now specify more than one event the contextmenu listens to? I specifically need the contextmenu to open both on right and left clcik....

Best Regards
0
Hristo
Telerik team
answered on 19 Jan 2012, 10:24 AM
Hello Anders,

RadContextMenu does not support listening to multiple events but you could do it manually. If you own the control then you could expose new event and set it as EventName on RadContextMenu. Then you will raise it on both left and right click.
Or you could attach the context menu on the element and leave the event name as the default value and manually attach handler on left click on the control. Then in the event handler you can get the context menu from the control and set its IsOpen property to true.

I hope that this will help you.

Greetings,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ContextMenu
Asked by
Anders
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Anders
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Share this question
or