# ComponentHost

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-view/prelude/struct-componenthost/

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

```rust
struct ComponentHost
```

A control that shows an element: a component hosted in XAML, an item of
a data template (`template`), or any element placed in
a tree of controls made otherwise.

The element is mounted when the host is given it and when the host is
attached to the visual tree again; it is disposed (its effects, hooks and
handlers end) when the host is detached from the visual tree. Components
inside read the `DataContext` of the host with
`use_data_context`.

In XAML, the `Component` property names a component registered with
[`register_component`](/docs/0.5.0/api/ferroui-view/function-register_component/).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L70)

## Members

- [`TYPE`](#assoc_const-type)
- [`to_ref`](#function-to_ref)
- [`component_property`](#function-component_property)
- [`construct`](#function-construct)
- [`new`](#function-new)
- [`with_view`](#function-with_view)
- [`component`](#function-component)
- [`set_component`](#function-set_component)
- [`set_view`](#function-set_view)
- [`set_parent_owner`](#function-set_parent_owner)

<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.View/component_host.rs#L75)

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

### to_ref

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

Returns a strong reference to this object.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L75)

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

### component_property

```rust
fn component_property() -> &'static StyledProperty<Option<String>>
```

Defines the `Component` property: the name of a component
registered with `register_component`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L106)

<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.View/component_host.rs#L134)

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

### new

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

A host with nothing to show.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L142)

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

### with_view

```rust
fn with_view<E: crate::IntoElement>(view: impl Fn() -> E + 'static) -> Ref<Self>
```

A host that shows the element `view` makes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L147)

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

### component

```rust
fn component(self: &Self) -> Option<String>
```

The name of the registered component the host shows.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L154)

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

### set_component

```rust
fn set_component(self: &Self, name: Option<String>)
```

Shows the registered component named `name`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L159)

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

### set_view

```rust
fn set_view<E: crate::IntoElement>(self: &Self, view: impl Fn() -> E + 'static)
```

Shows the element `view` makes, in place of what the host showed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L164)

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

### set_parent_owner

```rust
fn set_parent_owner(self: &Self, parent: Option<Owner>)
```

Mounts the content under `parent` (an owner whose contexts it sees)
instead of the owner that was current when the view was given.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/component_host.rs#L182)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`IntoValue<T>`](/docs/0.5.0/api/ferroui-view/builder/trait-intovalue/)
- [`IntoProp<T, Value>`](/docs/0.5.0/api/ferroui-view/builder/trait-intoprop/)
- `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`
- [`ControlImplExt`](/docs/0.5.0/api/ferroui-controls/trait-controlimplext/)
- `Deref`
- [`Upcast<T>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`Upcast<ComponentHost>`](/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/)
- [`FerroObjectImpl`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimpl/)
- [`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/)
- [`InputElementImpl`](/docs/0.5.0/api/ferroui-base/input/trait-inputelementimpl/)
- [`ControlImpl`](/docs/0.5.0/api/ferroui-controls/trait-controlimpl/)
- [`VisualImpl`](/docs/0.5.0/api/ferroui-base/trait-visualimpl/)

## Availability

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