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

MessageBox automatically closed after closing a RadWindow

2 Answers 690 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 15 Jan 2014, 03:21 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 made up of a MainWindow and a UserControl.
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 MessageBoxAutoClosed
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserControl1 l_userControl = new UserControl1();
 
            RadWindow l_hostWindow = new RadWindow()
            {
                Owner = System.Windows.Application.Current.MainWindow,
                WindowStartupLocation = WindowStartupLocation.CenterOwner
            };
 
            ScrollViewer l_scrollViewer = new ScrollViewer();
            l_scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            l_scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            l_scrollViewer.Content = l_userControl;
            l_hostWindow.Content = l_scrollViewer;
 
            l_hostWindow.Show();
            //l_hostWindow.Close();
 
            MessageBox.Show("MessageBox", "MessageBox", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
        }
    }
}

I do not have to click the OK button in the MessageBox to close it because the MessageBox is automatically closed.
Why ?

The MessageBox is not automatically closed when the following line is missing : l_hostWindow.Close();

Thank you in advance for your help

2 Answers, 1 is accepted

Sort by
0
Pascal GUERY
Top achievements
Rank 1
answered on 16 Jan 2014, 03:47 PM
The following line should not be commented in my previous code block : l_hostWindow.Close();

I have simplified my sample.
Here is the MainWindow's 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 MessageBoxAutoClosed
{
    /// <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()
            {
                Content = "Test"
            };
 
            l_hostWindow.Show();
            l_hostWindow.Close();
 
            MessageBox.Show("MessageBox", "MessageBox", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
        }
    }
}

0
Accepted
Kalin
Telerik team
answered on 20 Jan 2014, 09:40 AM
Hi Pascal,

We successfully reproduced the described issue. And it appears that this is a framework issue setting the owner of the MessageBox to be the recently open Window - the l_hostWindow in your scenario. So when the owner is closed and the MessageBox disappears. What I can suggest you in order to avoid that behavior is to implicitly set the owner of the MessageBox to be the MainWindow. Just replace the MessageBox in your code with the following one:

MessageBox.Show(this, "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 >>
Tags
Window
Asked by
Pascal GUERY
Top achievements
Rank 1
Answers by
Pascal GUERY
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or