Example #1
0
 private void Page_Appearing(object sender, EventArgs e)
 {
     if (IsEnabled && FocusElement != null)
     {
         FocusElement.Focus();
     }
 }
Example #2
0
        protected override void Invoke(VisualElement sender)
        {
            if (PlayOnce && _hasPlayed)
            {
                return;
            }

            if (Target == null)
            {
                Target = sender;
            }

            Target.Opacity = 0;
            Target.AnchorX = 0.5;
            Target.AnchorY = 0.5;

            var animationController = new Animation();

            switch (Direction)
            {
            case PushDirection.Top:
                VerticalAnimation(animationController);
                break;

            case PushDirection.Right:
                HorizontalAnimation(animationController);
                break;

            case PushDirection.Bottom:
                VerticalAnimation(animationController, true);
                break;

            case PushDirection.Left:
                HorizontalAnimation(animationController, true);
                break;

            default:
                return;
            }

            var fadeAnimation = new Animation(v => Target.Opacity = v, easing: Easing.CubicIn);

            animationController.Add(0.25, 0.65, fadeAnimation);

            animationController.Commit(Target, nameof(PushFade),
                                       16,
                                       (uint)Duration,
                                       finished: async(d, b) =>
            {
                if (FocusElement == null)
                {
                    return;
                }

                _hasPlayed = true;
                await Task.Delay(500);
                FocusElement.Focus();
            });
        }
Example #3
0
 public Form1()
 {
     InitializeComponent();
     this.KeyPreview = true;
     this.KeyPress  +=
         new KeyPressEventHandler(Form1_KeyPress);
     //FocusElement.Visible = false;
     FocusElement.Focus();
     this.FormBorderStyle = FormBorderStyle.FixedSingle;
     this.MaximizeBox     = false;
     this.MinimizeBox     = false;
     ResultLabel.Text     = "0";
 }
Example #4
0
        public static void SetElementFocus(this UIElement element, string specificElementName)
        {
            if (element == null)
            {
                throw new ArgumentNullException("Element");
            }

            //If a specific name is given, attempt to find a child with that name.
            //If one is found, either focus on it or its first focusable child.
            //If none of these are focusable, exit out.
            //If no specific name is given,
            //attempt to set focus on the given element or its first focusable child.
            UIElement FocusElement = null;

            if (!string.IsNullOrEmpty(specificElementName))
            {
                var NamedChild = element.FindAllVisualChildren <FrameworkElement>().Where(o => o.Name == specificElementName).FirstOrDefault();
                if (NamedChild.Focusable)
                {
                    FocusElement = NamedChild;
                }
                else
                {
                    FocusElement = NamedChild.FindAllVisualChildren <UIElement>().Where(o => o.Focusable).FirstOrDefault();
                }
            }
            else
            {
                if (element.Focusable)
                {
                    FocusElement = element;
                }
                else
                {
                    FocusElement = element.FindAllVisualChildren <UIElement>().Where(o => o.Focusable).FirstOrDefault();
                }
            }
            if (FocusElement == null)
            {
                return;
            }

            FocusElement.Focus();
            Keyboard.Focus(FocusElement);
        }
Example #5
0
        void AssociatedButtonClick(object sender, RoutedEventArgs e)
        {
            Keyboard.Focus(FocusElement);

            if (FocusElement is DatePicker)
            {
                // HACK: get the date-picker to focus the textbox-part by sending a Key.Up
                var eventArgs = new KeyEventArgs(
                    Keyboard.PrimaryDevice,
                    Keyboard.PrimaryDevice.ActiveSource,
                    0,
                    Key.Up)
                {
                    RoutedEvent = UIElement.KeyDownEvent
                };

                FocusElement.RaiseEvent(eventArgs);
            }
        }
Example #6
0
        void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            case (char)40:
            case (char)41:
            case (char)42:
            case (char)43:
            case (char)45:
            case (char)47:
            case (char)48:
            case (char)49:
            case (char)50:
            case (char)51:
            case (char)52:
            case (char)53:
            case (char)54:
            case (char)55:
            case (char)56:
            case (char)57:
                add(e.KeyChar.ToString());
                e.Handled = true;
                break;

            case (char)13:     //enter
                showResult();
                e.Handled = true;
                break;

            case (char)8:     //backspace
                removeLastChar();
                e.Handled = true;
                break;
            }
            FocusElement.Focus();
        }
Example #7
0
 private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
 {
     FocusElement?.Focus();
 }
Example #8
0
 /// <summary>
 /// 自动获得焦点方法
 /// </summary>
 /// <returns></returns>
 public ValueTask FocusAsync() => FocusElement.FocusAsync();
Example #9
0
 private void add(string stringToAdd)
 {
     Computations.Text += stringToAdd;
     FocusElement.Focus();
     //Computations.Focus();
 }