# Control

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/struct-control/

**struct** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
struct Control
```

Base class for controls.

The control class extends `InputElement` and adds the following
features:

- A `Tag` property to allow user-defined data to be attached to the
  control.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L108)

## Members

- [`find_data_template`](#function-find_data_template)
- [`TYPE`](#assoc_const-type)
- [`to_ref`](#function-to_ref)
- [`get_template_focus_target`](#function-get_template_focus_target)
- [`on_loaded`](#function-on_loaded)
- [`on_unloaded`](#function-on_unloaded)
- [`on_size_changed`](#function-on_size_changed)
- [`on_create_automation_peer`](#function-on_create_automation_peer)
- [`effective_context_flyout`](#function-effective_context_flyout)
- [`context_request_generation`](#function-context_request_generation)
- [`focus_adorner_property`](#function-focus_adorner_property)
- [`tag_property`](#function-tag_property)
- [`context_menu_property`](#function-context_menu_property)
- [`context_flyout_property`](#function-context_flyout_property)
- [`request_bring_into_view_event`](#function-request_bring_into_view_event)
- [`loaded_event`](#function-loaded_event)
- [`unloaded_event`](#function-unloaded_event)
- [`size_changed_event`](#function-size_changed_event)
- [`construct`](#function-construct)
- [`new`](#function-new)
- [`focus_adorner`](#function-focus_adorner)
- [`set_focus_adorner`](#function-set_focus_adorner)
- [`data_templates`](#function-data_templates)
- [`is_data_templates_initialized`](#function-is_data_templates_initialized)
- [`context_menu`](#function-context_menu)
- [`set_context_menu`](#function-set_context_menu)
- [`context_flyout`](#function-context_flyout)
- [`set_context_flyout`](#function-set_context_flyout)
- [`is_loaded`](#function-is_loaded)
- [`tag`](#function-tag)
- [`set_tag`](#function-set_tag)
- [`loaded`](#function-loaded)
- [`unloaded`](#function-unloaded)
- [`size_changed`](#function-size_changed)
- [`boxed`](#function-boxed)
- [`from_boxed`](#function-from_boxed)
- [`logical_from_boxed`](#function-logical_from_boxed)
- [`ensure_initialized`](#function-ensure_initialized)
- [`bring_into_view`](#function-bring_into_view)
- [`bring_into_view_rect`](#function-bring_into_view_rect)
- [`find_control`](#function-find_control)
- [`get_control`](#function-get_control)
- [`set_pseudo_class_from`](#function-set_pseudo_class_from)

<a id="function-find_data_template"></a>

### find_data_template

```rust
fn find_data_template(self: &Self, data: Option<&BoxedValue>, primary: Option<&Rc<dyn IDataTemplate>>) -> Option<Rc<dyn IDataTemplate>>
```

Find a data template that matches a piece of data.

`primary` is an optional primary template that can display the data.
Returns the data template or `None` if no matching data template was
found.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/templates/data_template_extensions.rs#L12)

<a id="assoc_const-type"></a>

### TYPE

```rust
const TYPE: &'static $crate::TypeInfo
```

The runtime type of this class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-to_ref"></a>

### to_ref

```rust
fn to_ref(self: &Self) -> $crate::Ref<Control>
```

Returns a strong reference to this object.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-get_template_focus_target"></a>

### get_template_focus_target

```rust
fn get_template_focus_target(self: &Self) -> Option<Ref<Control>>
```

Gets the element that receives the focus adorner.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-on_loaded"></a>

### on_loaded

```rust
fn on_loaded(self: &Self, e: &RoutedEventArgs)
```

Raises the `Loaded` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-on_unloaded"></a>

### on_unloaded

```rust
fn on_unloaded(self: &Self, e: &RoutedEventArgs)
```

Raises the `Unloaded` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-on_size_changed"></a>

### on_size_changed

```rust
fn on_size_changed(self: &Self, e: &SizeChangedEventArgs)
```

Raises the `SizeChanged` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-on_create_automation_peer"></a>

### on_create_automation_peer

```rust
fn on_create_automation_peer(self: &Self) -> Ref<AutomationPeer>
```

Returns a new, type-specific automation peer implementation for
the control.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-effective_context_flyout"></a>

### effective_context_flyout

```rust
fn effective_context_flyout(self: &Self, for_request: bool) -> Option<Ref<FlyoutBase>>
```

The flyout a context request on the control shows (`for_request`), or
that its keys and cancellation dismiss: `ContextFlyout` by default. A
control whose context flyout belongs to another element (a linked text
container) resolves it here, and may show none for a request. An
addition (`docs/porting/DEVIATIONS.md`, Popup).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-context_request_generation"></a>

### context_request_generation

```rust
fn context_request_generation(self: &Self) -> Option<u64>
```

A counter the control advances when it raises a newer context request
of its own while an older one is being handled; `None` by default. The
context menu and flyout drop the older request when it changed. An
addition (`docs/porting/DEVIATIONS.md`, Popup).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L124)

<a id="function-focus_adorner_property"></a>

### focus_adorner_property

```rust
fn focus_adorner_property() -> &'static StyledProperty<Option<Rc<dyn ITemplateOf<Option<Ref<Control>>>>>>
```

Defines the `FocusAdorner` property.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L330)

<a id="function-tag_property"></a>

### tag_property

```rust
fn tag_property() -> &'static StyledProperty<Option<BoxedValue>>
```

Defines the `Tag` property.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L330)

<a id="function-context_menu_property"></a>

### context_menu_property

```rust
fn context_menu_property() -> &'static StyledProperty<Option<Ref<ContextMenu>>>
```

Defines the `ContextMenu` property.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L330)

<a id="function-context_flyout_property"></a>

### context_flyout_property

```rust
fn context_flyout_property() -> &'static StyledProperty<Option<Ref<FlyoutBase>>>
```

Defines the `ContextFlyout` property.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L330)

<a id="function-request_bring_into_view_event"></a>

### request_bring_into_view_event

```rust
fn request_bring_into_view_event() -> &'static RoutedEvent<RequestBringIntoViewEventArgs>
```

Event raised when an element wishes to be scrolled into view.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L361)

<a id="function-loaded_event"></a>

### loaded_event

```rust
fn loaded_event() -> &'static RoutedEvent<RoutedEventArgs>
```

Defines the `Loaded` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L368)

<a id="function-unloaded_event"></a>

### unloaded_event

```rust
fn unloaded_event() -> &'static RoutedEvent<RoutedEventArgs>
```

Defines the `Unloaded` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L375)

<a id="function-size_changed_event"></a>

### size_changed_event

```rust
fn size_changed_event() -> &'static RoutedEvent<SizeChangedEventArgs>
```

Defines the `SizeChanged` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L382)

<a id="function-construct"></a>

### construct

```rust
fn construct() -> Self
```

Creates the class data; see `ferroui_base::FerroObject::construct`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L390)

<a id="function-new"></a>

### new

```rust
fn new() -> Ref<Self>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L394)

<a id="function-focus_adorner"></a>

### focus_adorner

```rust
fn focus_adorner(self: &Self) -> Option<Rc<dyn ITemplateOf<Option<Ref<Control>>>>>
```

The control's focus adorner.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L419)

<a id="function-set_focus_adorner"></a>

### set_focus_adorner

```rust
fn set_focus_adorner(self: &Self, value: Option<Rc<dyn ITemplateOf<Option<Ref<Control>>>>>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L423)

<a id="function-data_templates"></a>

### data_templates

```rust
fn data_templates(self: &Self) -> DataTemplates
```

The data templates for the control.

Each control may define data templates which are applied to the
control itself and its children.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L431)

<a id="function-is_data_templates_initialized"></a>

### is_data_templates_initialized

```rust
fn is_data_templates_initialized(self: &Self) -> bool
```

Whether the data templates collection has been created.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L436)

<a id="function-context_menu"></a>

### context_menu

```rust
fn context_menu(self: &Self) -> Option<Ref<ContextMenu>>
```

A context menu to the control.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L441)

<a id="function-set_context_menu"></a>

### set_context_menu

```rust
fn set_context_menu(self: &Self, value: impl Into<Nullable<ContextMenu>>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L445)

<a id="function-context_flyout"></a>

### context_flyout

```rust
fn context_flyout(self: &Self) -> Option<Ref<FlyoutBase>>
```

A context flyout to the control.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L455)

<a id="function-set_context_flyout"></a>

### set_context_flyout

```rust
fn set_context_flyout(self: &Self, value: impl Into<Nullable<FlyoutBase>>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L459)

<a id="function-is_loaded"></a>

### is_loaded

```rust
fn is_loaded(self: &Self) -> bool
```

Whether the control is fully constructed in the visual tree and both
layout and render are complete.

This is set to true while raising the `Loaded` event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L473)

<a id="function-tag"></a>

### tag

```rust
fn tag(self: &Self) -> Option<BoxedValue>
```

A user-defined object attached to the control.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L478)

<a id="function-set_tag"></a>

### set_tag

```rust
fn set_tag(self: &Self, value: Option<BoxedValue>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L482)

<a id="function-loaded"></a>

### loaded

```rust
fn loaded(self: &Self, handler: impl Fn(&Interactive, &RoutedEventArgs) -> () + 'static) -> RoutedEventHandlerToken
```

Occurs when the control has been fully constructed in the visual tree
and both layout and render are complete.

This event is guaranteed to occur after the control template is
applied and references to objects created after the template is
applied are available. This makes it different from
`on_attached_to_visual_tree` which doesn't have these references. This
event occurs at the latest possible time in the control creation
life-cycle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L495)

<a id="function-unloaded"></a>

### unloaded

```rust
fn unloaded(self: &Self, handler: impl Fn(&Interactive, &RoutedEventArgs) -> () + 'static) -> RoutedEventHandlerToken
```

Occurs when the control is removed from the visual tree.

This is API symmetrical with `loaded` and exists for compatibility
with other XAML frameworks; however, it behaves the same as
`on_detached_from_visual_tree`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L504)

<a id="function-size_changed"></a>

### size_changed

```rust
fn size_changed(self: &Self, handler: impl Fn(&Interactive, &SizeChangedEventArgs) -> () + 'static) -> RoutedEventHandlerToken
```

Occurs when the bounds (actual size) of the control have changed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L509)

<a id="function-boxed"></a>

### boxed

```rust
fn boxed(control: impl IntoRef<Control>) -> BoxedValue
```

The boxing convention for a control held in an untyped value (a
`Content`, a `Tag`, an item): the value holds a `Ref<Control>`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L518)

<a id="function-from_boxed"></a>

### from_boxed

```rust
fn from_boxed(value: &BoxedValue) -> Option<Ref<Control>>
```

The control held by an untyped value, if it holds one (`value as
Control` upstream). See `boxed`.

The value is a control whatever handle it holds it by: the
`Ref<Control>` of the boxing convention, the handle of another class
of the object model (a `Ref<Border>`, a `Ref<FerroObject>`), or an
interface handle that holds an object
(`ValueTypes::register_interface_object`); a value that a binding
passes on keeps the static type of its source.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L531)

<a id="function-logical_from_boxed"></a>

### logical_from_boxed

```rust
fn logical_from_boxed(value: &BoxedValue) -> Option<Ref<StyledElement>>
```

The logical element held by an untyped value, if it holds one
(`value as ILogical` upstream): an element held by any handle, as
`from_boxed` takes it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L542)

<a id="function-ensure_initialized"></a>

### ensure_initialized

```rust
fn ensure_initialized(self: &Self)
```

Ensures that the control is initialized and laid out when it is used
as the source of a visual brush while not attached to a visual root.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control.rs#L555)

<a id="function-bring_into_view"></a>

### bring_into_view

```rust
fn bring_into_view(self: &Self)
```

Tries to bring the control into view.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control_extensions.rs#L10)

<a id="function-bring_into_view_rect"></a>

### bring_into_view_rect

```rust
fn bring_into_view_rect(self: &Self, rect: Rect)
```

Tries to bring the control into view.

`rect` is the area of the control to being into view.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control_extensions.rs#L17)

<a id="function-find_control"></a>

### find_control

```rust
fn find_control<T: ObjectType>(self: &Self, name: &str) -> Option<Ref<T>>
```

Finds the named control in the scope of the specified control.

Returns the control or `None` if not found; panics if the control has
no parent name scope or the named control is of a different class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control_extensions.rs#L56)

<a id="function-get_control"></a>

### get_control

```rust
fn get_control<T: ObjectType>(self: &Self, name: &str) -> Ref<T>
```

Gets the named control in the scope of the specified control.

Panics if the control has no parent name scope or the named control
is not found.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control_extensions.rs#L67)

<a id="function-set_pseudo_class_from"></a>

### set_pseudo_class_from

```rust
fn set_pseudo_class_from(self: &Self, name: &str, trigger: &dyn IObservable<bool>) -> Subscription
```

Sets a pseudoclass of the control depending on an observable trigger.

Dropping the returned guard stops following the trigger; `Subscription::detach` keeps it
for the life of the trigger.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/control_extensions.rs#L78)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ControlImplExt`](/docs/0.5.0/api/ferroui-controls/trait-controlimplext/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/)
- `Any`
- [`InputElementImplExt`](/docs/0.5.0/api/ferroui-base/input/trait-inputelementimplext/)
- [`InteractiveImplExt`](/docs/0.5.0/api/ferroui-base/interactivity/trait-interactiveimplext/)
- [`LayoutableImplExt`](/docs/0.5.0/api/ferroui-base/layout/trait-layoutableimplext/)
- [`FerroObjectImplExt`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimplext/)
- [`StyledElementImplExt`](/docs/0.5.0/api/ferroui-base/trait-styledelementimplext/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- [`VisualImplExt`](/docs/0.5.0/api/ferroui-base/trait-visualimplext/)
- `ErasedDestructor`
- `IntoEither`
- `Deref`
- [`Upcast<T>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`Upcast<Control>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`StaticType`](/docs/0.5.0/api/ferroui-base/trait-statictype/)
- [`ObjectType`](/docs/0.5.0/api/ferroui-base/trait-objecttype/)
- [`Subclassable<T>`](/docs/0.5.0/api/ferroui-base/trait-subclassable/)
- [`DefaultConstructible`](/docs/0.5.0/api/ferroui-base/trait-defaultconstructible/)
- [`StyledElementImpl`](/docs/0.5.0/api/ferroui-base/trait-styledelementimpl/)
- [`LayoutableImpl`](/docs/0.5.0/api/ferroui-base/layout/trait-layoutableimpl/)
- [`InteractiveImpl`](/docs/0.5.0/api/ferroui-base/interactivity/trait-interactiveimpl/)
- [`FerroObjectImpl`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimpl/)
- [`VisualImpl`](/docs/0.5.0/api/ferroui-base/trait-visualimpl/)
- [`InputElementImpl`](/docs/0.5.0/api/ferroui-base/input/trait-inputelementimpl/)
- [`ControlImpl`](/docs/0.5.0/api/ferroui-controls/trait-controlimpl/)
- [`IDataTemplateHost`](/docs/0.5.0/api/ferroui-controls/templates/trait-idatatemplatehost/)
- [`ISetterValue`](/docs/0.5.0/api/ferroui-base/styling/trait-isettervalue/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
