public MainWindow() { //Settings must be load before XAML is parsed SettingsFile.LoadSettings(); // See comment in App.xaml.cs InitialHwMode = SettingsFile.Instance.HardwareAccelerationMode; InitializeComponent(); Closing += MainWindow_Closing; //Don't use this Window.OnClosing event, //datacontext might not be the same due to Avalonia internal handling data differently this.FindControl <ListBox>("ListboxIncludelist").AddHandler(DragDrop.DropEvent, DropInclude); this.FindControl <ListBox>("ListboxIncludelist").AddHandler(DragDrop.DragOverEvent, DragOver); this.FindControl <ListBox>("ListboxBlacklist").AddHandler(DragDrop.DropEvent, DropBlacklist); this.FindControl <ListBox>("ListboxBlacklist").AddHandler(DragDrop.DragOverEvent, DragOver); ApplicationHelpers.CurrentApplicationLifetime.Startup += MainWindow_Startup; ApplicationHelpers.CurrentApplicationLifetime.Exit += MainWindow_Exit; ApplicationHelpers.CurrentApplicationLifetime.ShutdownMode = ShutdownMode.OnExplicitShutdown; }