How to disable the ENTER key on one of the RadMenu item

16 posts, 0 answers
  1. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 27 Apr 2012 Link to this post

    • Hi,

      Basically, we want to disable the "Enter" key for one of the RadMenuItem. How can we trap the "Enter" key in code and not do anything for that?
       
      In more detail, the Grid is having a menu having the following options:
      - Show Configuration
      - Transpose
      - Export to Excel
      - Save Layout

      What we want to do is to access this menu in code and then disable the "Enter" key from "Export to Excel"  option. Here disabling means that when user press enter key when he is on "Export to excel", nothing should happen but if he presses the mouse click, it should work fine.

      Is there a way to trap the keyboard event on the RadMenuItem and discard the key press such that menuitemClick is only available via the MouseClick event. We have tried to hook on to Menu’s OnKeyUp/OnKeyDown but the control is not triggering the keyboard events. 

      How can we achieve that? Any help is highly appreciated.

      Thanks,
      Vijay 
  2. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 02 May 2012 Link to this post

    Hello Jeff,

    Unfortunately you are right and KeyUp and KeyDown is not triggered.  What you can do is create a custom menu item where you can override the OnKeyUp method. How to achieve that you can see in the attached project.

    Kind regards,
    Georgi
    the Telerik team

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

  3. Jeff
    Jeff avatar
    2 posts
    Member since:
    Nov 2011

    Posted 02 May 2012 Link to this post

    Hi,

    The project "SliverlightApplication1" doesnt have any files.So it doesnt load properly.Can you please attach the solution again with all the files in it?
  4. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 02 May 2012 Link to this post

    Hello Jeff,

    I am sending you the project again, although I have tried the zip I have sent you and it works just fine. When you unzip it you need to add your version of the controls (Telerik.Windows.Controls.dll and Telerik.Windows.Controls.Navigation.dll) in the project.

    All the best,
    Georgi
    the Telerik team

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

  5. Jeff
    Jeff avatar
    2 posts
    Member since:
    Nov 2011

    Posted 03 May 2012 Link to this post

    Georgi,

    I have tested the sample project which you have uploaded, unfortunately its not helping in disabling the ItemClick event on the menu item.

    we updated the sample to add an event handler to the RadMenu as shown below 

    <

    telerik:RadMenu VerticalAlignment="Top" ItemClick="RadMenu_ItemClick">
        <local:CustomMenuItem Header="Item 1">

         <telerik:RadMenuItem Header="Show Configuration" />

         <telerik:RadMenuItem Header="SubItem 2" />

     </local:CustomMenuItem>

     and the code behind 
     

     

    private void RadMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)

    {

        MessageBox.Show((e.Source as RadMenuItem).Header.ToString() );

    }

     

    public class CustomMenuItem : RadMenuItem  

    {

        protected override void OnKeyDown(KeyEventArgs e)

            {

            if (e.Key == Key.Enter) { e.Handled = true; }

                    else { base.OnKeyDown(e); }

        }

      protected override void OnKeyUp(KeyEventArgs e)

        {

            if (e.Key == Key.Enter) { e.Handled = true; }

                    else { base.OnKeyUp(e);  }

        }
    }


    we see that no matter what we do in the KeyUp/Down event the "ItemClick" event is always triggired. Would it be possible to help us suppress the "ItemClick" event for keyboard event espically Enter key?

  6. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 04 May 2012 Link to this post

    Hi Jeff,

    I edited the code you've sent and you can find it as an attached file. What I have done is basically made all MenuItems CustomMenuItems. So when you press Enter on a CustomMenuIItem , the Enter key is handled . This way you can choose where the enter key get handled and where it is not (by making CustomMenuItems or common MenuItem). As you can see in the attached video (although it is hard to see how I press Enter) when I press Enter the ItemClick is not triggered.

    Greetings,
    Georgi
    the Telerik team

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

  7. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 08 May 2012 Link to this post

    Hi Georgi,

    We are still facing the same problem. RadMenu_ItemClick is getting called for KeyDown as well as for Mouse Click.

    We are using framework4.0, and using 2009.3.1314.1030 version of Telerik assemblies. is this is the reason?
    If this is the case, could you please let me know the steps to take to surpress ItemClick event for 'Enter' key down OR any work around for this is more helpful.

    We are not in a position to upgrade to '2012.1.326.1050' due to all the breaking changes in the namespaces and its impact on the large codebase.

    Any help is highly appreciated.

    Regards,
    Ashok

  8. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 09 May 2012 Link to this post

    Hi Ashok,

    I have tried the project with 2009.3.1314.1030 version and it is indeed not working.
    Unfortunately with Silverlight 5 release the Silverlight 3 is not supported. I have traced the issue and it seems that everything works fine after Q2 2011 using 2011.2.712.1040 version. I couldn't think of any workaround and it seems that your best option is to upgrade.

    Kind regards,
    Georgi
    the Telerik team

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

  9. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 10 May 2012 Link to this post

    Hi Georgi,

    As per your statement, “Unfortunately with Silverlight 5 release, the Silverlight 3 is not supported”, does it means that you won’t provide any critical fixes (eg security issues) on the version that we have? Please confirm.

    Also, can you please provide
    an official written product life cycle support policy for Silverlight Controls?


    Thanks,
    Vijay
  10. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 11 May 2012 Link to this post

    Hello Vijay,

    Please check the release notes for Q3 2010 here , where we stated that the support for RadControls for Silverlight 3 is discontinued. Also you can find our road map at the following link:
    http://www.telerik.com/products/silverlight/roadmap.aspx.

    Kind regards,
    Georgi
    the Telerik team

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

  11. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 14 May 2012 Link to this post

    Hi Georgi ,

    I specified my previous and present code. We used CustomMenuItem that you suggested; but used only 'OnKeyDown', and not OnKeyUp
    When we assign the MenuItems list to the CustomMenuItem control through ItemsSource property , menu items of type ‘
    RadMenuItem’ are getting generated instead of ‘CustomMenuItem’; and not able to invoke any of the 'CustomMenuItem' events. If i do, or add the menuitems as specified in the Modified Code portion; then we are able to handle 'CustomMenuItem' events, like keyup or etc..


    Previous code:

    <customTelerikMenu:CustomMenuItem  x:Name="radWidgetMenuItem" Style="{StaticResource RadMenuItemStyle1}" ItemsSource="{Binding MenuItems}"

                                                       Cursor="Hand" ItemTemplate="{StaticResource WidgetMenuItemTemplate}">

                    <customTelerikMenu:CustomMenuItem.Icon>

                        <Path … … />

                    </customTelerikMenu:CustomMenuItem.Icon>

     

                </customTelerikMenu:CustomMenuItem>

     

    Modified code:

     

       StringBuilder sb = new StringBuilder();

                sb.Append("<telerik:RadMenu … ");

                sb.Append("<customTelerikMenu:IntuitionMenuItem>");

     

                foreach (MenuItem item in MenuViewModel.MenuItems)

                {

                    sb.Append("<customTelerikMenu:IntuitionMenuItem Header=\"" + item.Text + "\" />");

                }

     

                sb.Append("</customTelerikMenu:IntuitionMenuItem>");

                sb.Append("</telerik:RadMenu>");

     

                RadMenu radMenu = (RadMenu)(System.Windows.Markup.XamlReader.Load(sb.ToString()));

     

                expanderPanel.expanderMenu.LayoutRoot.Children.Add(radMenu);

     


    I believe that, this is not appropriate way. Do you have any suggestion/approach to handle this?

    Regards,
    Ashok

  12. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 15 May 2012 Link to this post

    Hello Ashok,

    In order to generate CustomMenuItem instead of MenuItem you need to override GetContainerForItemOverride, so your class should look something like this :

    public class CustomMenuItem : RadMenuItem
        {
            protected override void OnKeyDown(KeyEventArgs e)
            {
                if (e.Key == Key.Enter)
                {
                    e.Handled = true;
                }
                base.OnKeyDown(e);
            }
     
            protected override DependencyObject GetContainerForItemOverride()
            {
                return new CustomMenuItem();
            }
        }

    Also you need to do the same thing with the Menu ( create a custom menu witch inherits RadMenu and override GetContainerForItemOverride so it can return CustomMenuItem). So after these changes your initial code should work:

    <customTelerikMenu:CustomMenuItem  x:Name="radWidgetMenuItem" Style="{StaticResource RadMenuItemStyle1}" ItemsSource="{Binding MenuItems}"
     
                                                       Cursor="Hand" ItemTemplate="{StaticResource WidgetMenuItemTemplate}">
     
                    <customTelerikMenu:CustomMenuItem.Icon>
     
                        <Path … … />
     
                    </customTelerikMenu:CustomMenuItem.Icon>
     
      
     
                </customTelerikMenu:CustomMenuItem>


    Greetings,
    Georgi
    the Telerik team

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

  13. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 16 May 2012 Link to this post

    Hi Georgi,

    Based on your reply, can you please confirm that you (telerik team) will *not* patch our version to address this behavior?


    Thanks,
    Vijay
  14. Yana
    Admin
    Yana avatar
    4985 posts

    Posted 16 May 2012 Link to this post

    Hi Vijay,

    As Georgi stated we do not support Silverlight 3 anymore.
    If there is enough demand we may add an option which disable Enter key for RadMenuItems but it will be included only for Silverlight 5.

    Kind regards,
    Yana
    the Telerik team

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

  15. Jeff Lishingman
    Jeff Lishingman avatar
    18 posts
    Member since:
    Oct 2009

    Posted 17 May 2012 Link to this post

    Hi Georgi,

    We are able to block the keyboard events by making use of the CustomMenuItem and the newly specified override method 'GetContainerForItemOverride()' and previously specified 'OnKeyDown' method.

    Application started working with the initial code. But, we continued using RadMenu, instead of using the derived menu as we used click event/keyboard on menu items.
    I have a question on your reply that states, "Also you need to do the same thing with the Menu ( create a custom menu witch inherits RadMenu and override GetContainerForItemOverride so it can return CustomMenuItem). "
    In which case the Customized Menu returns the Custom Menu Item? Do we face any side effects if we dont use customized Menu?
    Any sample or snippet is more helpful for us to understand the problem better.

    Regards,
    Ashok
  16. Georgi
    Admin
    Georgi avatar
    364 posts

    Posted 22 May 2012 Link to this post

    Hello Jeff,

    As you have stated when you use ItemsSource="{Binding MenuItems}" it generates MenuItems instead of CustomMenu Items and overriding GetContainerForItemOverride() method fixes it. So you need to override this method of the Menu (using Custom Menu), only if you are using the same logic (binding ItemsSource) for the Menu. Therefore, if you don't set ItemsSouce for the RadMenu (so you don't have any MenuItems generated instead of CustomMenu Items) you don't need to use CustomMenu.

    All the best,
    Georgi
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top