public MainWindow() { InitializeComponent(); // Set this windows datacontext context = new MainInterface(); this.DataContext = context; this.SourceInitialized += Window_SourceInitialized; this.IsVisibleChanged += context.HandleController; this.Closing += Window_Closing; }