public SelectUser() { InitializeComponent(); this.DataContext = this; listOfUsers = DataStore.Users; foreach (var item in listOfUsers) { usersListBox.Items.Add(item); } SelectUserRunning = true; this.Activated += (sender, e) => { /* * Fires up when the UI is "InFocus" i.e. is the active window */ try { GrammarManipulator.ResponseBoxLoaded(); //Loads the UIGrammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Deactivated += (sender, e) => { /* * Fires up when the UI has "LostFocus" i.e. is no longer the active window */ try { GrammarManipulator.ResponseBoxDeloaded(); //unloads the UI grammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Closed += (sender, e) => { SelectUserRunning = false; }; GrammarFeeder.UserDialogOk += GrammarFeeder_UserDialogOk; GrammarFeeder.CloseResponseBoxEvent += GrammarFeeder_CloseResponseBoxEvent; }
static public void CreateResponseBox() { Thread thread = new Thread(() => { ResponseBox respBox = new ResponseBox(); respBox.Loaded += (sender, e) => { GrammarManipulator.ResponseBoxLoaded(); }; respBox.Closed += (sender, e) => { GrammarManipulator.ResponseBoxDeloaded(); respBox.Dispatcher.InvokeShutdown(); //so by closing the window the thread is shutdown as well. otherwise we get ghost thread which doesnt allow th application to exit }; respBox.Show(); System.Windows.Threading.Dispatcher.Run(); //for calling the dispatcher of the current window/uielement needed for running }); thread.SetApartmentState(ApartmentState.STA); //STA state in needed by wpf thread.Start(); //starts the thread }
public AddUser() { InitializeComponent(); userImage = new Image(); AddUserRunning = true; this.Activated += (sender, e) => { /* * Fires up when the UI is "InFocus" i.e. is the active window */ try { GrammarManipulator.ResponseBoxLoaded(); //Loads the UIGrammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Deactivated += (sender, e) => { /* * Fires up when the UI has "LostFocus" i.e. is no longer the active window */ try { GrammarManipulator.ResponseBoxDeloaded(); //unloads the UI grammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; GrammarFeeder.UserDialogOk += GrammarFeeder_UserDialogOk; GrammarFeeder.CloseResponseBoxEvent += GrammarFeeder_CloseResponseBoxEvent; }