问题
I have a console application. So I need Open a Window called "UserInterface.xaml" this is a Window.
I my class Program I have this:
class Program
{
[STAThread]
static void Main(string[] args)
{
var userInterface = new UserInterface();
userInterface .Show();
}
The problem is when the UserInterface.xaml is opened but then is closed immediately. And I need it for capture some data from user.
this is my class UserInterface:
public partial class UserInterface: Window
{
public UserInterface()
{
InitializeComponent();
}
........
}
How can I make the UserInterface window stay opened?
回答1:
Just use the ShowDialog() method instead.
UserInterface userInterface = new UserInterface();
userInterface.ShowDialog();
It will block until the form is manually or programmatically closed.
回答2:
Try to refine your Main() as below:
[STAThread]
static void Main(string[] args)
{
var userInterface = new UserInterface();
System.Windows.Application app = new System.Windows.Application();
app.Run(userInterface);
}
来源:https://stackoverflow.com/questions/6073658/open-a-window-since-programm-class