共用方式為


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 則是以非同步方式引發。 例如,如果您的 app 呼叫控制項的 Focus 方法,則 GettingFocus 會在呼叫期間引發,但在呼叫完成之後會引發 GotFocus。

如果在這些事件仍在反升時移動焦點,則會擲回例外狀況。

適用於

另請參閱