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

Window launched from RadMenuItem bound command opens deactivated

3 Answers 127 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Chris Boarman
Top achievements
Rank 1
Chris Boarman asked on 25 Mar 2010, 11:10 PM
Hello,

I recently switched my WPF app to use RadMenu and RadMenuItems. After making this change, I noticed a subtle difference in behavior.The problem is that when a new window is launched in response to a RadMenuitem click, it is immediately deactivated. I proved this by hooking the Deactivated event of the window I was opening. (See the stack trace below.)  I have confirmed that this problem is due to RadMenu/RadMenuItem  - changing back to WPF Menu/MenuItem made the problem go away. The deactivated window is a problem because immediately after launch users try to interact with the window, and there is a short delay to activate it again.

Background:
I have an MVVM WPF application. I open new windows by sending a message (mediator pattern) from the MainViewModel to the MainView. The MainView creates a new window, associates a view model to datacontext, and calls Show():

        ''' <summary> 
        ''' Handles displaying and replying to any received command messages 
        ''' </summary> 
        ''' <param name="message"></param> 
        ''' <remarks></remarks> 
        Private Sub HandleCommandMessage(ByVal message As CommandMessage) 
 
            If Not IsNothing(message) Then 'AndAlso message.Sender.GetType() Is GetType(MainViewModel) Then 
 
                ' Check if we are running on the UI thread. If not, call begin invoke 
                If Not _dispatcher.CheckAccess Then 
                    _dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, _ 
                                            New Action(Of CommandMessage)(AddressOf HandleCommandMessage), message) 
                Else 
                    Select Case message.Command 
 
                        Case Messages.ViewMessages.ShowDiagnosticsView.ToString() 
                            If IsNothing(_diagWindow) Then 
                                _diagWindow = New DiagnosticsView 
                                _diagWindow.Owner = Me 
                                _diagWindow.DataContext = Me.ViewModel.DiagViewModel 
                                _diagWindow.Show() 
                            End If 
 
                        Case Messages.ViewMessages.CloseDiagnosticView.ToString() 
                            If Not IsNothing(_diagWindow) Then 
                                _diagWindow.Close() 
                                _diagWindow = Nothing 
                            End If 
 
                       '... 
 
                        Case Else 
 
                    End Select 
                End If 
            End If 
 
        End Sub 
 

The MainViewModel has an ICommand instance called ShowDiagnosticviewCommand. This Command is bound to the RadMenuItem in my MainView as follows:
<!-- ... --> 
<telerik:RadMenuItem Header="Tools"
     <telerik:RadMenuItem Header="Diagnostics" Command="{Binding Path=ShowDiagnosticsViewCommand}" /> 
</telerik:RadMenuItem> 
<!-- ... ---> 
 

The MainViewModel has the following code:
       /// <summary> 
        /// Returns a command that opens the image view. 
        /// </summary> 
        public ICommand ShowDiagnosticsViewCommand 
        { 
            get 
            { 
                if (_showDiagnosticsViewCommand == null
                { 
                    _showDiagnosticsViewCommand = new RelayCommand((param) => this.ShowDiagnosticsView(), (param) => !this.DiagnosticsViewActive); 
                } 
                return _showDiagnosticsViewCommand; 
            } 
        } 
 
        private void ShowDiagnosticsView() 
        { 
            Messenger.Default.Send<CommandMessage>(new CommandMessage(this, Messages.ViewMessages.ShowDiagnosticsView.ToString())); 
 
        } 
 

Here is the call stack when i break on the Window_Deactivated event of the window being launched:

Call stack:
 
Imager.exe!CM.Imager.DiagnosticsView.Window_Deactivated(Object sender = {CM.Imager.DiagnosticsView}, System.EventArgs e = {System.EventArgs}) Line 57   Basic 
    [External Code]  
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.OnIsSubmenuOpenChanged(System.Windows.DependencyObject d = {Telerik.Windows.Controls.RadMenuItem Header:Tools Items.Count:7}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 1813 + 0xa bytes C# 
    [External Code]  
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.IsSubmenuOpen.set(bool value = false) Line 496 C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.CloseMenu() Line 944   C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.OnIsSelectedChanged(System.Windows.DependencyObject d = {Telerik.Windows.Controls.RadMenuItem Header:Tools Items.Count:7}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 1756    C# 
    [External Code]  
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.IsSelected.set(bool value = false) Line 648    C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.MenuBase.CurrentSelection.set(Telerik.Windows.Controls.RadMenuItem value = null) Line 302  C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.MenuBase.CloseAll() Line 327   C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.OnClickImpl() Line 1126    C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.OnClick() Line 1488    C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.ClickItem() Line 2527  C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.HandleMouseUp() Line 1098  C# 
    Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadMenuItem.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 1291   C# 
    [External Code]  
 

My guess is that somehow the window is losing focus back to the RadmenuItem after the bound command is fired, possibly on the RadmenuItem.OnIsSubmenuOpenChanged().

For now, I have switched back to using the default WPF menu. I prefer the Radmenu because of the nice theme support. Any help with this problem will be appreciated.

Thanks
Chris Boarman



3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 26 Mar 2010, 09:16 AM
Hi Chris Boarman,

This problem is fixed (we found similar issue this week). So with Latest Internal Build (that will be released later today) you will not see this strange behavior.

Let us know if you notice other issues using RadMenu.

Best wishes,
Hristo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
KubuliJohn
Top achievements
Rank 1
answered on 07 Jul 2010, 07:12 PM
When will this fix be released?  Reason I ask is we have the same problem and I'm running the 2010_1_603 build.

Ok, now I just tried the latest internal build 2010_1_702_35 and still the same problem.  A regular button on the main window opens the new window and it stays in front of the main window.  The same code from the item click event of the rad menu item opens the window but it appears behind the main window.
0
Hristo
Telerik team
answered on 08 Jul 2010, 03:49 PM
Hi John Haasbeek,

If you set Owner property of the new window to the current MainWindow then everything should be fine.
Other alternative is to call Show method in a Dispatcher so that it will open after the menu is closed.

I'm attaching a demo project with 2010_1_603 build that demonstrate both options.

Let me know if you need additional information.

Sincerely yours,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Menu
Asked by
Chris Boarman
Top achievements
Rank 1
Answers by
Hristo
Telerik team
KubuliJohn
Top achievements
Rank 1
Share this question
or