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

Menu not closed

9 Answers 474 Views
Menu
This is a migrated thread and some comments may be shown as answers.
sum sum
Top achievements
Rank 1
sum sum asked on 16 Nov 2009, 06:40 PM
HI guys,

I have menu items inside a dropdown button. Menus are bound to commands. The issue is once the item is clicked, commands are fired; but the menus are not closed afterwards. I have to click somewhere on the screen to make it close. How can I close the menu in the commands fired events?

thanks,

9 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 17 Nov 2009, 01:06 PM
Hi,

Instead of placing ContextMenu in a DropDown button I would recommend using the code from the following blog post, where the ContextMenu will close itself automatically:
http://blogs.telerik.com/valerihristov/posts/09-09-07/drop-down_menu_button_with_telerik_contextmenu_for_silverlight.aspx

Kind regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
sum sum
Top achievements
Rank 1
answered on 17 Nov 2009, 04:41 PM

Hi Guys,

If implementing ItemClick event, the menu closes. However, it is not closed when  binding menu items to commands. The sample you gave me is still ItemClick event.

0
Chris
Top achievements
Rank 1
answered on 05 Feb 2010, 10:08 AM
Hi

I have a similar problem and it is driving me nuts. Is there any resolution on this.

Here is my xaml. The command fires fine but the RadMenu stays open. It works if I handle the Click Event but I want my logic in the Presenter and not in the code behind.

<trn:RadMenu DockPanel.Dock="Top" x:Name="ConnectMenu" VerticalAlignment="Top" ClickToOpen="True">  
            <trn:RadMenuItem Header="Connect" ToolTip="Connect to e5 Instance" ItemsSource="{Binding Path=Instances}" > 
                <trn:RadMenuItem.ItemTemplate> 
                    <DataTemplate> 
                        <trn:RadMenuItem Command="{Binding DataContext.ConnectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type trn:RadMenu}}}"   
                                                   CommandParameter="{Binding Path=.}" 
                                         Header="{Binding Path=Name}" StaysOpenOnClick="False"/>  
                    </DataTemplate> 
                </trn:RadMenuItem.ItemTemplate> 
            </trn:RadMenuItem> 
        </trn:RadMenu> 

thanks
0
Hristo
Telerik team
answered on 05 Feb 2010, 01:14 PM
Hello Chris Wessels,

RadMenu doesn't close because you are placing RadMenuItems in RadMenuItem - from the DataTemplate.
Instead of ItemTemplate you should use ItemContainerStyle to apply style for dynamically created items and bind their properties in Style setters. Like this:
<trn:RadMenuItem.ItemContainerStyle>
    <Style TargetType="trn:RadMenuItem">
        <Setter Property="Command"
                Value="{Binding DataContext.ConnectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type trn:RadMenu}}}" />
        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
        <Setter Property="Header" Value="{Binding Path=Name}" />
        <Setter Property="StaysOpenOnClick" Value="False" />
    </Style>
</trn:RadMenuItem.ItemContainerStyle>

Let us know if you need more help.

Best wishes,
Hristo
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Chris
Top achievements
Rank 1
answered on 07 Feb 2010, 11:39 PM
Hi Hristo

Thanks so much for the quick response - that works beautifully. :-)

Regards
Chris
0
Calvin
Top achievements
Rank 1
answered on 07 Dec 2010, 10:25 PM
Are you suggesting that it is impossible to close a menu whenever MenuItems are nested within other MenuItems?   Is is possible to see the complete working project for the code snippet which you provide? 

I am using the Q2 RadMenu control. 

Thanks.
0
Hristo
Telerik team
answered on 09 Dec 2010, 09:32 AM
Hi Calvin,

You missed the context of the previous communication. If you take a look in the xaml you will see that the usage was incorrect.
RadMenu will close no matter which item you click.

Let us know if you need more details.

Regards,
Hristo
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Calvin
Top achievements
Rank 1
answered on 09 Dec 2010, 06:07 PM
I'll be happy to admit that I don't fully understand this issue which is why I asked my question.  I'll even admit that when I look at the xaml I do not see that the usage is incorrect which is why I asked if it is or is not OK to nest MenuItems within other MenuItems.  My Menu does not use a DataTemplate.  Every MenuItem contains the property  StaysOpenOnClick="False"

My Menu does not close no matter which item I click.  In other respects, it functions as I would expect it. 

Thanks.
0
Hristo
Telerik team
answered on 10 Dec 2010, 09:20 AM
Hello Calvin,

Could you please post the XAML declaring RadMenu and its items?
This way I will be able to help you faster.

All the best,
Hristo
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
Menu
Asked by
sum sum
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
sum sum
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Hristo
Telerik team
Calvin
Top achievements
Rank 1
Share this question
or