简体   繁体   中英

C# showdialog and this.close does not meet expectations because background is seen for a second when new window is shown

I'm using this code to open one window and close the other one. Its working but the problem is when one window is closed and the other one is opened background is seen for 1 second. I don't want it to be seen how can I solve it ? Should I use usercontrol and change it ? I don't want to use multiple usercontrols in one page because it complicates the program. So any other simple solution I would be glad.

    private void backPageButton_Click_1(object sender, RoutedEventArgs e)
    {
        MainWindow mWin = new MainWindow();
        this.Close();
        mWin.ShowDialog();
    }

Here is my code simple and When I change the orders like this

 private void backPageButton_Click_1(object sender, RoutedEventArgs e)
    {
        MainWindow mWin = new MainWindow();
        mWin.ShowDialog();
        this.Close();
    }

then it creates windows continually.

This would do it, use the second window to close the first

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(MainWindow otherWindow) : this()
        {
            if (otherWindow != null)
            {
                otherWindow.Close();
            }
        }

        public MainWindow()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mWin = new MainWindow(this);
            mWin.ShowDialog();
        }
    }
}

ps guessing you are trying to make a wizard style set of dialogs from the name of your button, I've had recent success using the WPF Toolkit Wizard control .

do this

private void backPageButton_Click_1(object sender, RoutedEventArgs e)
{
    this.Visible = false;
    MainWindow mWin = new MainWindow();
    mWin.ShowDialog();
    this.Close();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM