Skip to content

Latest commit

 

History

History
85 lines (51 loc) · 10.2 KB

frameworkelement.md

File metadata and controls

85 lines (51 loc) · 10.2 KB
-api-id -api-type
T:Microsoft.UI.Xaml.FrameworkElement
winrt class

Microsoft.UI.Xaml.FrameworkElement

-description

Provides a base element class for Windows Runtime UI objects. FrameworkElement defines common API that support UI interaction and the automatic layout system. FrameworkElement also defines API related to data binding, defining and examining the object tree, and tracking object lifetime.

-remarks

FrameworkElement is a base element: it's a class that many other Windows Runtime classes inherit from in order to support the XAML UI element model. Properties, methods and events that FrameworkElement defines are inherited by hundreds of other Windows Runtime classes.

Many common XAML UI classes derive from FrameworkElement, either directly or through intermediate base classes such as Panel or Control. Typically, you don't derive classes directly from FrameworkElement, because certain expected services for a class that is intended for a UI representation (such as template support) are not fully implemented there. More commonly used base classes for derived custom classes are:

FrameworkElement API and features

FrameworkElement extends UIElement, which is another base element, and adds support for various Windows Runtime feature areas.

Layout

The layout system recognizes all objects that derive from FrameworkElement to be elements that potentially participate in layout and should have a display area in the app UI. The layout system reads various properties that are defined at FrameworkElement level, such as MinWidth. Most UI elements use the FrameworkElement-defined Width and Height for their basic sizing information. FrameworkElement provides extensible methods for specialized layout behavior that panels and controls with content can override in their class implementations. For more info, see Define layouts with XAML.

Prominent API of FrameworkElement that support layout: Height, Width, ActualHeight, ActualWidth, Margin, MeasureOverride, ArrangeOverride, HorizontalAlignment, VerticalAlignment, LayoutUpdated.

Object lifetime events

You often want to know when an object is first loaded (loaded is defined as when an object becomes attached to an object tree that connects to the root visual). FrameworkElement defines events related to object lifetime that provide useful hooks for code-behind operations. For example you need object lifetime info to add child objects to a collection or set properties on child objects just prior to use, with assurance that the necessary objects in the object tree have already been instantiated from XAML markup. For more info, see Events and routed events overview.

Prominent API of FrameworkElement that support object lifetime events: Loaded, SizeChanged, Unloaded, OnApplyTemplate.

Data binding

The ability to set a value for a potentially inherited data context for a data binding is implemented by FrameworkElement. FrameworkElement also has API for establishing data binding in code rather than in XAML. For more info, see Data binding in depth.

Prominent API of FrameworkElement that support data binding: DataContext, DataContextChanged, SetBinding, GetBindingExpression.

XAML language and programming model integration

Usually your app's element structure resembles the XAML markup that you defined to create the UI, but sometimes that structure changes after the XAML was parsed. FrameworkElement defines the Name property and related API, which are useful for finding elements and element relationships at run-time. For more info, see XAML namescopes.

Prominent API of FrameworkElement that support XAML and programming model: Name, FindName, Parent, BaseUri, OnApplyTemplate.

Globalization

The FrameworkElement class defines the Language property and the FlowDirection property. For more info, see Globalizing your app.

Style and theme support

The FrameworkElement class defines the Style property and the RequestedTheme property. Also, the Resources property is used to define the page-level XAML resource dictionaries that typically define styles and templates, as well as other shared resources. For more info, see Styling controls and ResourceDictionary and XAML resource references.

FrameworkElement dependency properties

Many of the read-write properties of the FrameworkElement base element class are dependency properties. Dependency properties support some of the basic programming model features for a Windows App SDK app using C++ or C#, such as styles and templates, data binding, XAML resource references, and property-changed logic. For more info on dependency properties and the features they support, see Dependency properties overview.

FrameworkElement derived classes

FrameworkElement is the parent class for several immediately derived classes that distinguish several broad classifications of UI elements. Here are some of the notable derived classes:

-examples

-see-also

UIElement, Creating a UI, Dependency properties overview