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

Main window in background after closing a RadWindow

3 Answers 585 Views
Window
This is a migrated thread and some comments may be shown as answers.
Pascal GUERY
Top achievements
Rank 1
Pascal GUERY asked on 16 Jan 2014, 03:50 PM
Hi everyone,

I am developing a WPF application in my company.
I use RadControls for WPF Q3 2013 trial version.

I have written a sample project.
The MainWindow contains a Button and I have written an handler to the Button's Click event.

Here is the MainWindow's code-behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
 
namespace MainWindowInBackground
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadWindow l_hostWindow = new RadWindow()
            {
                Owner = System.Windows.Application.Current.MainWindow,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Content = "Test"
            };
 
            l_hostWindow.Show();
 
            MessageBox.Show("MessageBox", "MessageBox", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
        }
    }
}

The attached picture 1.png shows the application before closing the RadWindow.
The attached picture 2.png shows the application after closing the RadWindow.
The main window has been automatically put in background - behind all other running applications's window - after closing the RadWindow.
Why ?

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 20 Jan 2014, 09:49 AM
Hello Pascal,

The issue you are facing here is related with the issue from your other forum post. You would just need to set the owner of the MessageBox to be the MainWindow in order to have the MainWindow focused afterwards. You can just replace the MessageBox in your code with the following and it will work as expected:

MessageBox.Show(System.Windows.Application.Current.MainWindow, "MessageBox", "MessageBox", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);

Hope this works for you.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Pascal GUERY
Top achievements
Rank 1
answered on 22 Jan 2014, 01:20 PM
Hi,

I have changed the MainWindow's code-behind in my sample project.
Here is the new code-behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
 
namespace MainWindowInBackground
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadWindow l_hostWindow = new RadWindow()
            {
                Owner = System.Windows.Application.Current.MainWindow,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Content = "Test"
            };
 
            l_hostWindow.Show();
 
            RadWindow l_hostWindow2 = new RadWindow()
            {
                Owner = System.Windows.Application.Current.MainWindow,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Content = "Test 2"
            };
 
            l_hostWindow2.Show();
            l_hostWindow2.Close();
        }
    }
}

When the user clicks the button :
  1. A RadWindow R1 is created and shown
  2. A RadWindow R2 is created and shown
  3. The R2 RadWindow is closed

I have done the following actions :
  1. I have launched the application. Screenshot taken after the action : Attached file 1.png
  2. I have clicked the button. A pop-up window titled "RadControls for WPF Trial" was displayed because my application uses RadControls for WPF Q3 2013 Trial Version assemblies. Screenshot taken after the action : Attached file 2.png
  3. I have closed the "RadControls for WPF Trial" pop-up window by clicking the Annuler button. Screenshot taken after the action : Attached file 3.png
  4. I have closed the R1 RadWindow. Screenshot taken after the action : Attached file 4.png
  5. I have clicked the button. The R1 RadWindow was displayed. Screenshot taken after the action : Attached file 5.png
  6. I have closed the R1 RadWindow. The main window has been automatically put in background. Screenshot taken after the action : Attached file 6.png

Can you please explain me why the main window has been automatically put in background after action 6 ?
Thank you in advance for your help
0
Accepted
Kalin
Telerik team
answered on 24 Jan 2014, 01:26 PM
Hi Pascal,

We are already aware of the described behavior and it is actually issue cause by framework itself. If you try to recreate the same scenario but using the regular Windows instead of RadWindow you will observe the same behavior:

var wind1 = new Window()
{
    Owner = System.Windows.Application.Current.MainWindow,
    WindowStartupLocation = WindowStartupLocation.CenterOwner,
    Content = "Test"
 
};
wind1.Show();
var wind2 = new Window()
{
    Owner = System.Windows.Application.Current.MainWindow,
    WindowStartupLocation = WindowStartupLocation.CenterOwner,
    Content = "Test 2"
};
wind2.Show();
wind2.Close();

It appears this comes from the first Window Owner - if you remove it, it works as expected. However what I can suggest as workaround is to remove the Owner of the first Window and set its IsTopmost property to true, this way you will avoid the issue and will still have the first Window above the MainWindow.

Hope this will work for you.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Window
Asked by
Pascal GUERY
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Pascal GUERY
Top achievements
Rank 1
Share this question
or