Clicking menu item does not close menu

4 posts, 0 answers
  1. Bryan
    Bryan avatar
    28 posts
    Member since:
    Jul 2008

    Posted 12 Apr 2013 Link to this post

    Hey there. I have a project with a RadMenu and it's menu Items are defined like so:


            <Style x:Key="MenuItemBaseStyle" TargetType="telerik:RadMenuItem">
                <Setter Property="Header" Value="{Binding Content}" />
                <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />
                <Setter Property="ItemsSource" Value="{Binding}" />
            </Style>

            <Style x:Key="MenuItemLinkStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemLinkControlTemplate}" />
                <Setter Property="Margin" Value="4 3 4 2" />
            </Style>

    And the Template is defined:

            <ControlTemplate x:Key="MenuItemLinkControlTemplate" TargetType="telerik:RadMenuItem">
                <StackPanel>
                    <Button Click="ButtonBase_OnClick" Content="{Binding Content}" Style="{StaticResource LinkButtonMenu}" />
                </StackPanel>
            </ControlTemplate>


    I know it looks weird that It's a button, but there's a very specific reason we're doing that due to some issues we had after the last release. It was working fine prior to having to change it and I need it to work with the current Template I have defined for it. I tried setting the StaysOpenOnClick  property to false in the style as well and the issue still persisted. Thanks in advanced for the help.
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 15 Apr 2013 Link to this post

    Hello Bryan,

    When you use a button, it has its own handler for Click event, which is preventing the Click to reach RadMenuItem. This way you click the button, but RadMenuItem doesn't receive the click. That's the reason why the menu is not closed. One option to resolve this issue is to find the parent RadMenuItem of the button in the click event handler and set IsSubmenuOpen property to false. This will close the submenu.
    I'm not sure if this is the best solution for your case as I do not have full details for your scenario. Could you be more specific why you need a button inside RadMenuItem and what are the issues that you had with our last release?

    I'm looking forward to hearing from you.

    All the best,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Bryan
    Bryan avatar
    28 posts
    Member since:
    Jul 2008

    Posted 15 Apr 2013 Link to this post

    After updating to latest version of WPF RadControls, there was an issue with our app that popped up, where on occasion, when a user would try and click a link in our RadMenu, nothing would occur and the click event for it was not firing off. 

    Also, after adding the IsSubmenuOpen to false, it still is not closing.

                var button = (Button)e.OriginalSource;

                var stackPanel   = button.Parent as StackPanel;
                if (stackPanel != null) 
                {
                    var menuItem = (RadMenuItem) stackPanel.TemplatedParent;
                    menuItem.IsSubmenuOpen = false;
                    string header = Convert.ToString(menuItem.Header);
              
                    _viewModel.NavigateTo(header);
                }
            }
  5. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 16 Apr 2013 Link to this post

    Hello Bryan,

    Do you mean that you've installed our Service Pack release (2013.1 403) and in some cases your RadMenuItem has not received click? As we have not observed such problem, can you isolate the problem in a project and send it to us?
    Now for your code - I've noticed you are setting IsSubmenuOpen to the RadMenuItem which is holding the button. IsSubmenuOpen property opens/closes the child popup of each RadMenuItem. So if you want to close a particular popup, you will have to find the item in which is your RadMenuItem and set IsSubmenuOpen to its parent RadMenuItem.

    Hopefully this makes sense. I'm looking forward to hearing from you.

    Regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top