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

Clicking menu item does not close menu

3 Answers 305 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 13 Apr 2013, 12:20 AM
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.

3 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 15 Apr 2013, 08:18 AM
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.

0
Bryan
Top achievements
Rank 1
answered on 15 Apr 2013, 04:06 PM
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);
            }
        }
0
Rosen Vladimirov
Telerik team
answered on 16 Apr 2013, 11:54 AM
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.

Tags
Menu
Asked by
Bryan
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or