protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var window = new MobileApplication(); var viewModel = new MobileApplicationViewModel(); // When the ViewModel asks to be closed, // close the window. EventHandler handler = null; handler = delegate { viewModel.RequestClose -= handler; window.Close(); }; viewModel.RequestClose += handler; // Allow all controls in the window to // bind to the ViewModel by setting the // DataContext, which propagates down // the element tree. window.DataContext = viewModel; window.Show(); }