简体   繁体   中英

C# WPF Application - Show second window

I am trying to show another WPF window in my project, but it keeps giving me an error CS1061 (missing using directive). My code is representated below.

My project consists of two pages, one main, and one window that should open after the click.

The code of the click is where I get the error. It gives the error code showed before...

the click:

        }
        private void Win_Click(object sender, RoutedEventArgs e)
        {
            var form = new Window();
            form.ShowDialog();        //ERROR  CS1061
        }

I am using following Using-Directives:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Navigation;
using System.Linq;
using System.Text;
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.Shapes;
using System.Windows.Forms;

I also tried changing my click code to this, but I still get the same error:

        }
        private void Win_Click(object sender, RoutedEventArgs e)
        {
            var form = new Window();
            form.Show();        //ERROR  CS1061
        }

I hope you can help me finding the issue with my code snippet, why I keep getting that error. Thanks for taking your time to help me!

I would suggest creating a named WPF window, creating an instance of that window (instead of a generic window), then running that code after replacing the window with the named wpf window.

Edit: I would also set the owner of your new named WPF window according to what object "owns" it.

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