In a simple MVVM approach, I associate MainWindow with a ViewModel, overriding OnStartup in App.xaml.
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow window = new MainWindow(); var viewModel = new MainWindowViewModel(); window.DataContext = viewModel; window.Show(); } }
This results in two instances of MainWindow when the WPF application starts. Won't this lead to one, as I redefine the launch?
One of the windows displays the correct DataContext (ViewModel), and the other does not.
source share