This question is locked. New answers and comments are not allowed.
Hello,
I have a RadMenuItem that creates it's subitems asynchronously after the user hovers the menu (the first time only)... Unfortunately, after they hover the menu item and then the subitems are created, I need to "jiggle" the mouse to get the menu to actually open. Is there a way to force the submenu to open after the subitems are created?
Here's my sample code...
A custom control defined like this:
Notice that when you hover the top level menu item, the worker is executed (to simulate an async retrieval of menu items) at that point you need to move the mouse (even a single pixel) to get the menu to actually open...
I have a RadMenuItem that creates it's subitems asynchronously after the user hovers the menu (the first time only)... Unfortunately, after they hover the menu item and then the subitems are created, I need to "jiggle" the mouse to get the menu to actually open. Is there a way to force the submenu to open after the subitems are created?
Here's my sample code...
A custom control defined like this:
<Style TargetType="local:SomeCustomControl"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:SomeCustomControl"> <telerik:RadMenu ShowDelay="0" HideDelay="0"> <telerik:RadMenuItem x:Name="rmi" Header="^" ItemsSource="{TemplateBinding MyList}"> </telerik:RadMenuItem> </telerik:RadMenu> </ControlTemplate> </Setter.Value> </Setter> </Style>using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Telerik.Windows.Controls; using System.ComponentModel; using System.Threading; using System.Collections.ObjectModel; namespace SilverlightApplication36 { public class SomeCustomControl : Control { private bool _eventsRegistered = false; public SomeCustomControl() { DefaultStyleKey = typeof(SomeCustomControl); } private RadMenuItem _rootMenuItem = null; public override void OnApplyTemplate() { base.OnApplyTemplate(); if (_rootMenuItem == null) { _rootMenuItem = GetTemplateChild("rmi") as RadMenuItem; if (!_eventsRegistered && _rootMenuItem != null) { _eventsRegistered = true; _rootMenuItem.MouseEnter += _rootMenuItem_MouseEnter; } } } void _rootMenuItem_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { if (_rootMenuItem.Items.Count == 0) { _rootMenuItem.MouseEnter -= _rootMenuItem_MouseEnter; //Simulate the delay to retrieve menu items using a BackgroundWorker()... BackgroundWorker w = new BackgroundWorker(); w.DoWork += new DoWorkEventHandler(w_DoWork); w.RunWorkerCompleted += new RunWorkerCompletedEventHandler(w_RunWorkerCompleted); w.RunWorkerAsync(); } } void w_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(3000); } void w_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { SetValue ( SomeCustomControl.MyListProperty, new ObservableCollection<RadMenuItem> { new RadMenuItem() { Header = "aaa", Icon = new Border() { BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.Purple), BorderBrush = new SolidColorBrush(Colors.Orange), Height = 16, Width = 16 } }, new RadMenuItem() { Header = "bbb", Icon = new Border() { BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.Purple), BorderBrush = new SolidColorBrush(Colors.Orange), Height = 16, Width = 16 } }, new RadMenuItem() { Header = "ccc", Icon = new Border() { BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.Purple), BorderBrush = new SolidColorBrush(Colors.Orange), Height = 16, Width = 16 } }, new RadMenuItem() { Header = "ddd", Icon = new Border() { BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.Purple), BorderBrush = new SolidColorBrush(Colors.Orange), Height = 16, Width = 16 } } } ); //Would like to "open" the menu here now that it has values!!! //_rootMenuItem.OpenMePlease! } public static readonly DependencyProperty MyListProperty = DependencyProperty.Register("MyList", typeof(ObservableCollection<Telerik.Windows.Controls.RadMenuItem>), typeof(SomeCustomControl), null); public ObservableCollection<RadMenuItem> MyList { get { return (ObservableCollection<RadMenuItem>)GetValue(MyListProperty); } set { SetValue(MyListProperty, value); } } } } Notice that when you hover the top level menu item, the worker is executed (to simulate an async retrieval of menu items) at that point you need to move the mouse (even a single pixel) to get the menu to actually open...