wforl
wforl

Reputation: 889

Custom MessageBox using Window

In regard to the code below.

If I use the built in MessageBox, then the previous MessageBox has to be closed before the next one is displayed.

How can I achieve this with a Window so that I can create a custom message box? I tried using the ShowDialog method, but whilst this does create Modal windows, it still shows them all at the same time cascaded.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(MainWindow_Loaded);
    }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        for (int i = 0; i < 3; ++i)
        {
            Dispatcher.BeginInvoke(new Action(() => ShowDialog2()));
        }
    }

    void ShowDialog2()
    {
        //MessageBox.Show("A message");

        Window w = new Window() { Width = 200, Height = 200, Content = "SomeText" };
        w.ShowDialog();
    }
}

Upvotes: 1

Views: 148

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81313

Open first instance of window with ShowDialog and consequent instances of window with Show method.

Show open a non-modal window whereas ShowDialog open modal window.

Upvotes: 1

Related Questions