public CPackConsole(string projectRootDirectory) { DataContext = new CPackConsoleViewModel(projectRootDirectory); Service = new CPackService(); PreviousCommands = new List <string>(); InitializeComponent(); CommandTextBox.Focus(); DialogContext = SynchronizationContext.Current; MyContext.PropertyChanged += (sender, args) => { if (args.PropertyName == "TextBoxEnabled") { Thread.Sleep(200); DialogContext.Post(val => { if (CommandTextBox.IsEnabled) { CommandTextBox.Focus(); } }, sender); } }; MyContext.Exit += MyContext_Exit; }