Frage

Sorry for confusing title =D

In WindowsForms I have Main method, which I can use to do something before creating or displaying main form. For example, processing command line parameters, showing splash window and preloading configuration, having several windows shown one after each other, main loop (when there is a repeatable working sequence, then Main is pretty good place to put there do{}while), etc.

Which is the best analog for such Main method in WPF?

I tried to use Application.Startup event, but it has some issues.

I could think of creating wpf application programmatically somehow (then I should be unbound from xaml autogenerated Main and can have my own). But this all sounds too complicated. I probably missing something very simple.

War es hilfreich?

Lösung 2

Solution is ... do everything in the Main.

For this I have to disable auto-generating Main (by setting App.xaml property BuildAction to Page, instead of default ApplicationDefinition) and then I can create own Main inside Application class:

public partial class App : Application
{
    [STAThread]
    public static void Main()
    {
    }
}

There I have full control over when and how to display windows, do initialization, deinit and such.

Andere Tipps

Moving from WinForms development to WPF development can involve a little bit of a change of mindset. I would look into WPF and MVVM, there are plenty of resources on the web.

After that, you should start looking at the various frameworks which build on this, such as Prism, Caliburn.Micro, MVVMLight etc, which all have various tutorials and documentation around building WPF applications with splash screens and composite windows.

For what it's worth, protected override void OnStartup in App.xaml.cs is where you'd want to "do something, before anything", like, show a splash screen before loading your main screen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top