开发者

WPF: Keeping an object running?

开发者 https://www.devze.com 2022-12-12 06:16 出处:网络
I\'m having problems understanding how WPF app.xaml works. Is it like Main method in winforms programing?

I'm having problems understanding how WPF app.xaml works. Is it like Main method in winforms programing?

What I want is a MainController class which keeps track of my Window object. For example:

public MainController()
{
  _windowMain = new WindowMain(this);
}

public WindowMain GetWindowMain
{
  ge开发者_Python百科t { _windowMain; }
}

And so on with all the windows I have in my project. But where should my MainController be initialized?


Check the StartupUri property of the App.xaml file. It links in a Window's XAML file within your project to be launched at startup.

If you want to avoid this, then I believe you can override a method in App.xaml.cs to launch the window explicitly via your controller.

You should understand that the compiler makes a class called 'App' that overrides System.Windows.Application by compiling your App.xaml and App.xaml.cs files. Check the documentation for that class to learn more about the lifecycle management of your WPF application.

0

精彩评论

暂无评论...
验证码 换一张
取 消