コード例 #1
0
        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);
             }
         }
     });
 }
コード例 #3
0
        private static void Element_Loaded(object sender, RoutedEventArgs e)
        {
            var target = GetStartFocusedControl((DependencyObject)sender);

            ControlFocus.GiveFocus(target);
        }