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

How to close RadMenuItem programmatically from cs file.

3 Answers 257 Views
Menu
This is a migrated thread and some comments may be shown as answers.
mohan choudhary
Top achievements
Rank 1
mohan choudhary asked on 21 Dec 2009, 02:51 PM
<telerikNavigation:RadMenu ClickToOpen="True" VerticalAlignment="Top" BorderThickness="0" Background="Transparent" telerik:StyleManager.Theme="{StaticResource Theme}" > 
                                <telerikNavigation:RadMenuItem Click="RadMenuItem_Click" VerticalAlignment="Top" BorderThickness="0" Background="Transparent" StaysOpenOnClick="False" > 
                                    <telerikNavigation:RadMenuItem.Icon  > 
                                        <Image Source="../../Images/downArrowGray.png"/> 
                                    </telerikNavigation:RadMenuItem.Icon> 
                                    <telerikNavigation:RadMenuItem Name="rmiEdit" Header="Edit" Click="EditItem_Click" BorderThickness="0"></telerikNavigation:RadMenuItem> 
                                    <telerikNavigation:RadMenuItem  Name="rmiDelete"  Header="Delete" Command="{Binding Path=ParentCalendarViewModel.DeleteCalendarCommand}" Click="DeleteItem_Click" BorderThickness="0"></telerikNavigation:RadMenuItem> 
                                    <telerikNavigation:RadMenuItem  Name="rmiInactivate"  Header="Inactivate" BorderThickness="0" ></telerikNavigation:RadMenuItem> 
                                    <telerikNavigation:RadMenuItem  Name="rmiAddCalendarDate" BorderThickness="0" Command="{Binding Path=ParentCalendarViewModel.AddNewCalendarDateRow}" Header="Add a Calendar Date" ></telerikNavigation:RadMenuItem> 
                                    <telerikNavigation:RadMenuItem  Name="rmiAddNote" BorderThickness="0" Header="Add a Note" ></telerikNavigation:RadMenuItem> 
                                    <telerikNavigation:RadMenuItem  Name="rmiViewHistory" BorderThickness="0" Header="View History" ></telerikNavigation:RadMenuItem> 
                                </telerikNavigation:RadMenuItem> 
 
                            </telerikNavigation:RadMenu> 

The above is my RadMenuItem, how can I close the submenu programmatically from cs code file.
when the user clicks on the RadMenuItem , the submenu opens, but on some conditions how can I close it from cs file code.  and I have access to the RadMenuItem object.

The following is the code attached with the scenario -

<UserControl x:Class="ContextMenu_ShowFromCode.Page" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:core="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
             xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"   
             xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    <Grid x:Name="LayoutRoot" Background="White"
        <StackPanel Orientation="Vertical"
            
 
            <telerikNavigation:RadMenu ClickToOpen="True" VerticalAlignment="Top" BorderThickness="0" Background="Transparent" > 
                <telerikNavigation:RadMenuItem Click="RadMenuItem_Click" VerticalAlignment="Top" BorderThickness="0" Background="Transparent"  > 
                    <telerikNavigation:RadMenuItem.Icon  > 
                        <Image Source="../../Images/downArrowGray.png"/> 
                    </telerikNavigation:RadMenuItem.Icon> 
                    <telerikNavigation:RadMenuItem Name="rmiEdit" Header="Edit" Click="EditItem_Click" BorderThickness="0"></telerikNavigation:RadMenuItem> 
                    <telerikNavigation:RadMenuItem  Name="rmiDelete"  Header="Delete" BorderThickness="0"></telerikNavigation:RadMenuItem> 
                    <telerikNavigation:RadMenuItem  Name="rmiInactivate"  Header="Inactivate" BorderThickness="0" ></telerikNavigation:RadMenuItem> 
                    <telerikNavigation:RadMenuItem  Name="rmiAddCalendarDate" BorderThickness="0" Header="Add a Calendar Date" ></telerikNavigation:RadMenuItem> 
                    <telerikNavigation:RadMenuItem  Name="rmiAddNote" BorderThickness="0" Header="Add a Note" ></telerikNavigation:RadMenuItem> 
                    <telerikNavigation:RadMenuItem  Name="rmiViewHistory" BorderThickness="0" Header="View History" ></telerikNavigation:RadMenuItem> 
                </telerikNavigation:RadMenuItem> 
 
            </telerikNavigation:RadMenu> 
             
            <TextBox Name="txtbxTemp" LostFocus="TextBox_LostFocus" ></TextBox
        </StackPanel> 
    </Grid> 
</UserControl> 
 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Telerik.Windows.Controls; 
 
namespace ContextMenu_ShowFromCode 
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
        } 
 
      
        private void RadMenuItem_Click(object sender, RoutedEventArgs e) 
        { 
             
        } 
 
        private void TextBox_LostFocus(object sender, RoutedEventArgs e) 
        { 
            // I want to hide the already opened submenu here. 
            // And I have the RadMenuItem object available. 
        } 
    } 
 

In the above text box the user enters some value and hits the RadMenuItem, the TextBox_LostFocus is fired and the submenu is also opened.  But I don't want the RadMenuItem's submenu to open up.






3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 23 Dec 2009, 09:14 AM
Hi mohan choudhary,

Are you focusing the textbox from code on MenuItem click?
Open/Close of RadMenu from code is not supported yet. But if you open then menu you cannot click another control on the page unless menu is closed.

Regards,
Hristo
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
John Thompson
Top achievements
Rank 2
answered on 30 Jan 2010, 04:28 PM
The only solution I have been able to work out is using ItemSource binding to create the RadMenuItems and the setting the ItemsSource to null when in the ItemClick event.
0
troy
Top achievements
Rank 1
answered on 26 Mar 2010, 03:50 PM
if you have the RadMenuItem, you can close it like this:

 

 

RadMenuItemAutomationPeer mip = new RadMenuItemAutomationPeer(menuItemRoot);

 

mip.Invoke();

where menuItemRoot is your menu item.  The Invoke() basically calls the default action which is click, so if the menu is open, it will close it.

You can also use this same method to open a menu, but to do this, you have to start at the root and work your way to your menu item.

Tags
Menu
Asked by
mohan choudhary
Top achievements
Rank 1
Answers by
Hristo
Telerik team
John Thompson
Top achievements
Rank 2
troy
Top achievements
Rank 1
Share this question
or