Share via


GettingFocusEventArgs.TrySetNewFocusedElement(DependencyObject) 方法

定义

尝试将焦点重定向到指定元素而不是原始目标元素。

public:
 virtual bool TrySetNewFocusedElement(DependencyObject ^ element) = TrySetNewFocusedElement;
bool TrySetNewFocusedElement(DependencyObject const& element);
public bool TrySetNewFocusedElement(DependencyObject element);
function trySetNewFocusedElement(element)
Public Function TrySetNewFocusedElement (element As DependencyObject) As Boolean

参数

element
DependencyObject

要对其设置焦点的 对象。

返回

Boolean

bool

如果重定向焦点操作,则为 True;否则为 false。

Windows 要求

设备系列
Windows 10, version 1803 (在 10.0.17134.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v6.0 中引入)

注解

GotFocus 路由事件在元素获得焦点后在元素上引发,而 LostFocus 路由事件在元素失去焦点后在元素上引发。

GettingFocusLosingFocus 路由事件在焦点更改发生之前发生,这使应用程序能够修改或取消焦点更改行为。

GettingFocusLosingFocus 是同步引发的,而 GotFocusLostFocus 是异步引发的。 例如,如果应用调用控件的 Focus 方法,则会在调用期间引发 GettingFocus,但在调用完成后引发 GotFocus。

如果在这些事件仍在冒泡时移动焦点,则会引发异常。

适用于

另请参阅