UIElement 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
UIElement 是大部分Windows 執行階段 UI 物件的基類,具有視覺外觀,而且可以在應用程式的使用者介面中處理基本輸入。
public ref class UIElement : DependencyObject
public ref class UIElement : DependencyObject, IAnimationObject
public ref class UIElement : DependencyObject, IAnimationObject, IVisualElement
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject, IAnimationObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject, IAnimationObject, IVisualElement
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject, IAnimationObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject, IAnimationObject, IVisualElement
Public Class UIElement
Inherits DependencyObject
Public Class UIElement
Inherits DependencyObject
Implements IAnimationObject
Public Class UIElement
Inherits DependencyObject
Implements IAnimationObject, IVisualElement
- 繼承
- 衍生
- 屬性
- 實作
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
備註
UIElement 是基底元素:它是許多其他Windows 執行階段類別繼承自的類別,以支援 XAML UI 元素模型。 UIElement 定義的屬性、方法和事件是由數百個其他Windows 執行階段類別所繼承。
雖然 UIElement 會定義焦點報告 (GotFocus、 LostFocus) 的事件,但 UIElement 不會定義 API 以程式設計方式設定焦點。 這項功能是由 Control 類別所定義。
UIElement 不會公開公用建構函式。 一般而言,您不會直接從 UIElement 或 FrameworkElement 衍生類別。 衍生自訂類別的基類較常會是這些類別:
- 例如,未密封 (的特定控制項 TextBox)
- 控制項基類 (Control、ContentControl、UserControl)
- 頁面、框架) (導覽元素
- 面板類別 (基類 Panel或特定的非密封實作,例如 Grid)
UIElement 類別會當做Windows 執行階段 API 中許多屬性和方法的類型參數使用。 例如,Border的Child屬性會採用單一 UIElement,代表Border周圍繪製的專案。 您可以為這類屬性提供任何 UIElement 衍生元素,包括您定義的自訂控制項。
UIElementCollection類別提供 UIElement 專案的強型別集合。 UIElementCollection是做為包含數個子項目之物件的屬性類型,例如任何Panel類別的Children屬性。
UIElement API 和功能
UIElement 會擴充DependencyObject,這是另一個基底元素,並新增對各種Windows 執行階段功能區域的支援。
回應使用者互動的輸入和事件
UI 中可見元素的大部分輸入行為都是在 UIElement 類別中定義。 這包括鍵盤、滑鼠、觸控、拖放和焦點互動的事件。 如需詳細資訊,請參閱 處理指標輸入、 鍵盤互動和 自訂使用者互動。
支援輸入和使用者互動的 UIElement 醒目 API:
- 指標事件:PointerPressed、 PointerReleased、 PointerMoved、 PointerEntered、 PointerExited
- 金鑰處理事件:KeyDown、 KeyUp
- Focus:GotFocus、 LostFocus
- 指標擷取:CapturePointer、 PointerCanceled、 PointerCaptureLost、 ReleasePointerCapture、 PointerCaptures
- 拖放:DragOver、 Drop、 DragEnter、 DragLeave、 AllowDrop
- 影響基本輸入處理方式的屬性:IsHitTestVisible、 AllowDrop
手勢和操作
手勢和操作也是處理輸入和使用者互動的方法。 API 會在這裡個別列出,因為這些事件代表系統如何與裝置層級輸入動作互動,並將其解譯為使用者互動。 操作是處理動態多點觸控互動的方式,例如捏合和延展。 手勢和操作一起提供觸控模式,以便與 UWP app 進行觸控互動。 如需詳細資訊,請參閱 自訂使用者互動 和 觸控互動設計。
支援手勢和操作的 UIElement 醒目 API:
- 手勢事件:DoubleTapped、 Holding、 RightTapped、 Tapped
- 操作事件:ManipulationCompleted、 ManipulationDelta、 ManipulationInertiaStarting、 ManipulationStarted、 ManipulationStarting
- 影響手勢和操作處理方式的屬性:IsHoldingEnabled 和其他 Is*Enabled、 ManipulationMode
基本外觀
Visibility和Opacity屬性經常用來調整 UI 中元素的外觀,特別是在樣式、範本和視覺狀態內。 Clip、RenderTransform和Transitions屬性對於產生互動和不同外觀的 UI 元素都很有用。
基本版面配置
UIElement 類別提供版面配置特性的起點,包括 DesiredSize 和 Arrange 和 Measure 方法等屬性。 FrameworkElement 新增更多版面配置功能。 如需詳細資訊,請參閱使用 XAML 和FrameworkElement定義版面配置。
路由事件
UIElement 的大部分輸入事件都是 路由事件。 路由事件會啟用內建事件處理通知系統,如此一來,如果事件維持未處理狀態,父物件就可以處理來自物件樹狀結構中子物件的輸入事件。 此輸入事件行為適用于輸入區域群組,以及控制組合。 如需詳細資訊,請參閱事件與路由事件概觀。
支援路由事件之 UIElement 的醒目 API: AddHandler、 RemoveHandler、*事件 屬性。
其他平臺支援
- OnCreateAutomationPeer 可讓類別針對其 Microsoft UI 自動化支援使用自訂 AutomationPeer 。
- RenderTransform、TransformToVisual、Projection、CompositeMode、CacheMode和FindSubElementsForTouchTargeting適用于進階 UI 配置案例。
UIElement 相依性屬性
UIElement 基底專案類別的許多讀寫屬性都是相依性屬性。 相依性屬性支援一些使用 C++、C# 或 Visual Basic 之 UWP app 的基本程式設計模型功能,例如樣式和範本、資料系結、XAML 資源參考和屬性變更邏輯。 如需相依性屬性及其支援功能的詳細資訊,請參閱 相依性屬性概觀。
UIElement 衍生類別
直接衍生自 UIElement 的唯一Windows 執行階段類別是FrameworkElement。 For a list of the classes that derive from FrameworkElement, see the "FrameworkElement derived classes" section of the FrameworkElement reference topic.
版本歷程記錄
Windows 版本 | SDK 版本 | 新增值 |
---|---|---|
1607 | 14393 | AccessKey |
1607 | 14393 | AccessKeyDisplayDismissed |
1607 | 14393 | AccessKeyDisplayRequested |
1607 | 14393 | AccessKeyInvoked |
1607 | 14393 | AccessKeyScopeOwner |
1607 | 14393 | CoNtextCanceled |
1607 | 14393 | ContextFlyout |
1607 | 14393 | CoNtextRequested |
1607 | 14393 | ExitDisplayModeOnAccessKeyInvoked |
1607 | 14393 | IsAccessKeyScope |
1703 | 15063 | GettingFocus |
1703 | 15063 | GettingFocusEvent |
1703 | 15063 | HighContrastAdjustment |
1703 | 15063 | KeyTipHorizontalOffset |
1703 | 15063 | KeyTipPlacementMode |
1703 | 15063 | KeyTipVerticalOffset |
1703 | 15063 | 車燈 |
1703 | 15063 | LosingFocus |
1703 | 15063 | LosingFocusEvent |
1703 | 15063 | NoFocusCandidateFound |
1703 | 15063 | NoFocusCandidateFoundEvent |
1703 | 15063 | StartBringIntoView |
1703 | 15063 | StartBringIntoView (BringIntoViewOptions) |
1703 | 15063 | TabFocusNavigation |
1703 | 15063 | XYFocusDownNavigationStrategy |
1703 | 15063 | XYFocusKeyboardNavigation |
1703 | 15063 | XYFocusLeftNavigationStrategy |
1703 | 15063 | XYFocusRightNavigationStrategy |
1703 | 15063 | XYFocusUpNavigationStrategy |
1709 | 16299 | CharacterReceived |
1709 | 16299 | CharacterReceivedEvent |
1709 | 16299 | GetChildrenInTabFocusOrder |
1709 | 16299 | KeyboardAccelerators |
1709 | 16299 | OnProcessKeyboardAccelerators |
1709 | 16299 | PreviewKeyDown |
1709 | 16299 | PreviewKeyDownEvent |
1709 | 16299 | PreviewKeyUp |
1709 | 16299 | PreviewKeyUpEvent |
1709 | 16299 | ProcessKeyboardAccelerators |
1709 | 16299 | TryInvokeKeyboardAccelerator |
1803 | 17134 | BringIntoViewRequested |
1803 | 17134 | BringIntoViewRequestedEvent |
1803 | 17134 | CoNtextRequestedEvent |
1803 | 17134 | KeyboardAcceleratorPlacementMode |
1803 | 17134 | KeyboardAcceleratorPlacementTarget |
1803 | 17134 | KeyTipTarget |
1803 | 17134 | OnBringIntoViewRequested |
1803 | 17134 | OnKeyboardAcceleratorInvoked |
1803 | 17134 | RegisterAsScrollPort |
1809 | 17763 | CanBeScrollAnchor |
1809 | 17763 | CenterPoint |
1809 | 17763 | OpacityTransition |
1809 | 17763 | PopulatePropertyInfo |
1809 | 17763 | PopulatePropertyInfoOverride |
1809 | 17763 | 旋轉 |
1809 | 17763 | RotationAxis |
1809 | 17763 | RotationTransition |
1809 | 17763 | 調整 |
1809 | 17763 | ScaleTransition |
1809 | 17763 | StartAnimation |
1809 | 17763 | StopAnimation |
1809 | 17763 | TransformMatrix |
1809 | 17763 | 翻譯 |
1809 | 17763 | TranslationTransition |
1903 | 18362 | ActualOffset |
1903 | 18362 | ActualSize |
1903 | 18362 | 陰影 |
1903 | 18362 | UIContext |
1903 | 18362 | XamlRoot |
屬性
方法
事件
AccessKeyDisplayDismissed |
發生于不應再顯示便捷鍵時。 |
AccessKeyDisplayRequested |
發生于使用者要求顯示存取金鑰時。 |
AccessKeyInvoked |
發生于使用者完成存取金鑰序列時。 |
BringIntoViewRequested |
在這個專案或其其中一個子系上呼叫 StartBringIntoView 時發生。 |
CharacterReceived |
發生于輸入佇列收到單一撰寫字元時。 |
ContextCanceled |
當內容輸入手勢繼續進入操作手勢時發生,以通知專案不應開啟內容飛出視窗。 |
ContextRequested |
發生于使用者完成內容輸入手勢時,例如按一下滑鼠右鍵。 |
DoubleTapped |
發生于此元素的點擊測試區域上發生未處理的 DoubleTap 互動時。 |
DragEnter |
當輸入系統報告具有這個專案作為目標的基礎拖曳事件時發生。 |
DragLeave |
當輸入系統報告基礎拖曳事件,並將這個專案當做原點時發生。 |
DragOver |
在輸入系統回報以此項目作為可能置放目標的基礎拖曳事件時發生。 |
DragStarting |
發生于起始拖曳作業時。 |
Drop |
輸入系統報告其下以這個項目作為置放目標的置放事件時發生。 |
DropCompleted |
發生于以這個專案做為來源結束的拖放作業時。 |
GettingFocus |
發生于 UIElement 收到焦點之前。 此事件會同步引發,以確保事件反升時不會移動焦點。 |
GotFocus |
發生于 UIElement 收到焦點時。 這個事件會以非同步方式引發,因此焦點可以在反升完成之前再次移動。 |
Holding |
發生于此元素的點擊測試區域上發生未處理的 保留 互動時。 |
KeyDown |
在 UIElement 有焦點時按下鍵盤按鍵時發生。 |
KeyUp |
發生于 UIElement 有焦點時放開鍵盤按鍵時。 |
LosingFocus |
發生于 UIElement 失去焦點之前。 此事件會同步引發,以確保事件反升時不會移動焦點。 |
LostFocus |
發生于 UIElement 失去焦點時。 此事件會以非同步方式引發,因此焦點可以在反升完成之前再次移動。 |
ManipulationCompleted |
發生于 UIElement 上的操作完成時。 |
ManipulationDelta |
輸入裝置在操作期間變更位置時發生。 |
ManipulationInertiaStarting |
在操作和慣性開始的時候,只要輸入裝置不與 UIElement 物件接觸便發生。 |
ManipulationStarted |
當輸入裝置開始在 UIElement 進行操作時發生。 |
ManipulationStarting |
發生於第一次建立操作處理器時。 |
NoFocusCandidateFound |
發生于使用者嘗試透過索引標籤或方向箭號移動焦點 () ,但焦點不會移動,因為不會在移動方向找到任何焦點候選項目。 |
PointerCanceled |
發生于讓連絡人異常失去連絡人的指標時。 |
PointerCaptureLost |
發生于這個專案先前保留的指標擷取移至另一個專案或其他地方時。 |
PointerEntered |
發生于指標進入這個專案的點擊測試區域時。 |
PointerExited |
發生于指標離開這個專案的點擊測試區域時。 |
PointerMoved |
當指標在指標保留在這個專案的點擊測試區域中時移動時發生。 |
PointerPressed |
發生于指標裝置在這個專案內起始 Press 動作時。 |
PointerReleased |
發生于先前起始 按下 動作的指標裝置放開時,同時在此元素內。 請注意, 按下動作的 結尾不保證會引發 PointerReleased 事件;其他事件可能會改為引發。 如需詳細資訊,請參閱。 |
PointerWheelChanged |
發生于指標滾輪的差異值變更時。 |
PreviewKeyDown |
在 UIElement 有焦點時按下鍵盤按鍵時發生。 |
PreviewKeyUp |
發生于 UIElement 有焦點時放開鍵盤按鍵時。 |
ProcessKeyboardAccelerators |
發生于按下 鍵盤快速鍵 (或快速鍵) 時。 |
RightTapped |
發生于在指標位於 元素上方時發生右鍵輸入回應時。 |
Tapped |
發生于此元素的點擊測試區域上發生未處理的 Tap 互動時。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應