0

我正在尝试制作自己的 wpf TextBox,当它获得焦点时捕获鼠标。我的代码:

public FocusedTextBox()
        {
            AddHandler(Mouse.PreviewMouseDownOutsideCapturedElementEvent, new MouseButtonEventHandler(OnPreviewMouseDownOutsideCapturedElement));
        }

protected override void OnGotFocus(RoutedEventArgs e)
        {
            base.OnGotFocus(e);
            this.CaptureMouse();
        }

protected override void OnLostMouseCapture(MouseEventArgs e)
        {
            base.OnLostMouseCapture(e);
        }

但是立即OnGotFocus结束,该OnLostMouseCapture方法被调用,我不知道为什么。但在OnLostMouseCapture两者内部FocusManager.GetFocuseElement(window)Keyboard.FocuseElement返回FocusedTextBox. 如何保持鼠标捕获FocusedTextBox

4

0 回答 0