private static void OnHasFocusChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as FrameworkElement;

            if (element == null)
            {
                throw new InvalidOperationException("The FocusBehavior.HasFocus only can be attached to an FrameworkElement");
            }

            if ((bool)e.NewValue)
            {
                ControlFocus.GiveFocus(element);
                element.LostFocus += Element_LostFocus;
            }
        }
示例#2
0
 private void SelectText(TextBox box, bool selectAll, string text)
 {
     ControlFocus.GiveFocus(box, delegate
     {
         if (selectAll)
         {
             box.SelectAll();
         }
         else if (!string.IsNullOrEmpty(text))
         {
             int pos = box.Text.IndexOf(text);
             if (pos > 0 &&
                 box.Text.Contains(text))
             {
                 box.Select(pos, text.Length);
             }
         }
     });
 }
        private static void Element_Loaded(object sender, RoutedEventArgs e)
        {
            var target = GetStartFocusedControl((DependencyObject)sender);

            ControlFocus.GiveFocus(target);
        }
        private void SetFocusOn(ControlFocus selection)
        {
            try
            {
                switch (selection)
                {
                    case ControlFocus.RegexText:
                        txtRegex.Focus();
                        break;
                    case ControlFocus.InputText:
                        tabSctInputPart.SelectedTab= tabInputText;
                        txtInput.Focus();
                        break;
                    case ControlFocus.ReplaceWithText:
                        tabSctInputPart.SelectedTab= tabReplaceWith;
                        txtReplaceWith.Focus();
                        break;
                    case ControlFocus.MatchesTree:
                        tabControl1.SelectedTab= tabMatches;
                        Tree.Focus();

                        break;
                    case ControlFocus.ReplaceOutput:
                        tabControl1.SelectedTab= tabOutput;
                        txtOutputReplace.Focus();

                        break;
                    case ControlFocus.SplitsOutput:
                        tabControl1.SelectedTab= tabSplits;
                        lvSplits.Focus();

                        break;

                    default:
                        ;
                        break;
                }
            }
            catch(Exception )
            {

            }
        }