none
WPF C# MDI Modal Window sample

All replies

  • WPF makes it hard on purpose. Maybe you have better end-user experience experts than Micosoft, who knows.
    MSMVP VC++
    Saturday, May 09, 2009 6:01 PM
    Moderator
  • At first, in large applications modal windows, can be shown from background threads. But in  WPF you can create UI elements, only in STA thread. Actually, modal window must block main window and other opened windows.
    For accessing STA thread from other threads you should use this: "Application.Current.Dispatcher.Invoke" (Application always start in STA thread), then for blocking all windows set Owner property in popup win to the main window.
    Example. Create some window, which will be used as popup, f.e. DialogBox. Start it in the STA thread, and set Owner property:

            public static void ShowMessage(string message)
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate
                {
                    DialogBox dialogBox = new DialogBox(message);
                    dialogBox.Owner = Application.Current.MainWindow;
                    dialogBox.ShowDialog();
                });
            }
    You can use this static method from any thread, any place in your application.
    That works properly for me
    Hope this helps )
    Friday, January 22, 2010 4:36 PM