Example #1
0
        private void FocusTextBox(TextBox textBox)
        {
            DeferredAction deferredAction = null;

            deferredAction = DeferredAction.Create(() =>
            {
                if (textBox == null || App.Current == null || App.Current.MainWindow == null)
                {
                    return;
                }

                textBox.Focus();
                textBox.SelectAll();
                FocusManager.SetFocusedElement(App.Current.MainWindow, textBox);
                Keyboard.Focus(textBox);

                if (textBox.IsVisible == false || textBox.IsKeyboardFocused)
                {
                    deferredAction.Dispose();
                }
                else
                {
                    deferredAction.Defer(TimeSpan.FromSeconds(0.25));
                }
            });

            deferredAction.Defer(TimeSpan.FromSeconds(0.25));
        }
 public void Dispose()
 {
     if (!disposed)
     {
         if (_deferredAction != null)
         {
             _deferredAction.Dispose();
         }
         _repository.ParticipantAdded   -= OnParticipantAdded;
         _repository.ParticipantUpdated -= HandleParticipantUpdate;
         _ageUpdater.OnAgeIncrement     -= OnNewAge;
         Mediator.Unregister("MainWindowClosing", OnMainWindowClosing);
         disposed = true;
         GC.SuppressFinalize(this);
     }
 }