ContextMenu works perfectly, but only through mouse use?

11 posts, 0 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 04 Apr 2011 Link to this post

    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>
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 04 Apr 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 04 Apr 2011 Link to this post

    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.
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Apr 2011 Link to this post

    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
  6. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 05 Apr 2011 Link to this post

    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
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 06 Apr 2011 Link to this post

    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
  8. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 06 Apr 2011 Link to this post

    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
  9. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 11 Apr 2011 Link to this post

    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
  10. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 11 Apr 2011 Link to this post

    I will (sometime during the week). Thanks for letting me know!
  11. Christian
    Christian avatar
    52 posts
    Member since:
    Apr 2011

    Posted 16 Jan 2012 Link to this post

    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
  12. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 19 Jan 2012 Link to this post

    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 >>

Back to Top
UI for WPF is Visual Studio 2017 Ready