MessageBox automatically closed after closing a RadWindow

3 posts, 1 answers
  1. Pascal GUERY
    Pascal GUERY avatar
    38 posts
    Member since:
    Apr 2010

    Posted 15 Jan 2014 Link to this post

    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. Pascal GUERY
    Pascal GUERY avatar
    38 posts
    Member since:
    Apr 2010

    Posted 16 Jan 2014 Link to this post

    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);
            }
        }
    }

  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 20 Jan 2014 Link to this post

    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 >>
Back to Top