Migrated the code behind logic to the viewmodel in MainWindow.xaml