# VisualStateManager

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

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

```rust
struct VisualStateManager
```

Manages the visual states of controls and the transitions between them.

The visual states of an element are the `visual_state_groups_property`
attached to the root of its visual states: for a templated control the root of its template,
for a user control (or any content control, or content page) whose template has none, the
control that is its content. `go_to_state` makes a state the current state of its group.

A custom manager derives from this class, overrides
`go_to_state_core` and is set on the root with
`set_custom_visual_state_manager`.

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

## Members

- [`TYPE`](#assoc_const-type)
- [`to_ref`](#function-to_ref)
- [`go_to_state_core`](#function-go_to_state_core)
- [`visual_state_groups_property`](#function-visual_state_groups_property)
- [`custom_visual_state_manager_property`](#function-custom_visual_state_manager_property)
- [`construct`](#function-construct)
- [`new`](#function-new)
- [`get_visual_state_groups`](#function-get_visual_state_groups)
- [`set_visual_state_groups`](#function-set_visual_state_groups)
- [`get_custom_visual_state_manager`](#function-get_custom_visual_state_manager)
- [`set_custom_visual_state_manager`](#function-set_custom_visual_state_manager)
- [`go_to_state`](#function-go_to_state)
- [`raise_current_state_changing`](#function-raise_current_state_changing)
- [`raise_current_state_changed`](#function-raise_current_state_changed)

<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/visual_state/visual_state_manager.rs#L38)

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

### to_ref

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

Returns a strong reference to this object.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L38)

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

### go_to_state_core

```rust
fn go_to_state_core(self: &Self, control: &Ref<Control>, template_root: &Ref<Control>, state_name: &str, group: Option<&Ref<VisualStateGroup>>, state: Option<&Ref<VisualState>>, use_transitions: bool) -> bool
```

Changes the state of `group` to `state` (WinUI's overridable `GoToStateCore`).

`template_root` is the element that has the groups; `group` and `state` are the
group and the state named `state_name`, or `None` when no group has a state of that
name (a custom manager is called either way). The base method changes the state when
both are given and returns whether it did.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L38)

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

### visual_state_groups_property

```rust
fn visual_state_groups_property() -> &'static AttachedProperty<Option<VisualStateGroupCollection>>
```

Defines the attached `VisualStateGroups` property: the groups of visual states of an
element. `get_visual_state_groups`
creates the collection when the element has none, which is what markup's property
element syntax (`<VisualStateManager.VisualStateGroups>`) adds the groups to.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L99)

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

### custom_visual_state_manager_property

```rust
fn custom_visual_state_manager_property() -> &'static AttachedProperty<Option<Ref<VisualStateManager>>>
```

Defines the attached `CustomVisualStateManager` property: the manager that changes the
states of the groups of the element it is set on.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L99)

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

### construct

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L129)

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

### new

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L133)

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

### get_visual_state_groups

```rust
fn get_visual_state_groups(element: &Control) -> VisualStateGroupCollection
```

The groups of visual states of `element`; an empty collection is created and set when the
element has none (WinUI's `GetVisualStateGroups`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L139)

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

### set_visual_state_groups

```rust
fn set_visual_state_groups(element: &Control, value: Option<VisualStateGroupCollection>)
```

Sets the groups of visual states of `element`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L149)

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

### get_custom_visual_state_manager

```rust
fn get_custom_visual_state_manager(element: &Control) -> Option<Ref<VisualStateManager>>
```

The custom manager set on `element`, if any.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L154)

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

### set_custom_visual_state_manager

```rust
fn set_custom_visual_state_manager(element: &Control, value: Option<Ref<VisualStateManager>>)
```

Sets the custom manager of the groups of `element`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L159)

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

### go_to_state

```rust
fn go_to_state(control: &Control, state_name: &str, use_transitions: bool) -> bool
```

Makes the state named `state_name` the current state of its group (WinUI's `GoToState`).

The groups are those of the root of the visual states of `control` (see the type). Returns
`false`, and changes nothing, when there is no such root or no group has a state of that
name (names are case-sensitive); a custom manager on the root decides instead. Entering
the current state again with `use_transitions == false` applies its values again; with
transitions it does nothing. Either way it returns `true`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L170)

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

### raise_current_state_changing

```rust
fn raise_current_state_changing(self: &Self, group: &Ref<VisualStateGroup>, old_state: Option<Ref<VisualState>>, new_state: Option<Ref<VisualState>>, control: Option<Ref<Control>>)
```

Raises `CurrentStateChanging` of `group` (for derived managers; WinUI's protected
`RaiseCurrentStateChanging`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L193)

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

### raise_current_state_changed

```rust
fn raise_current_state_changed(self: &Self, group: &Ref<VisualStateGroup>, old_state: Option<Ref<VisualState>>, new_state: Option<Ref<VisualState>>, control: Option<Ref<Control>>)
```

Raises `CurrentStateChanged` of `group` (for derived managers; WinUI's protected
`RaiseCurrentStateChanged`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/visual_state/visual_state_manager.rs#L205)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`VisualStateManagerImplExt`](/docs/0.5.0/api/ferroui-controls/visual_state/trait-visualstatemanagerimplext/)
- `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`
- [`FerroObjectImplExt`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimplext/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- `Deref`
- [`Upcast<T>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`Upcast<VisualStateManager>`](/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/)
- [`VisualStateManagerImpl`](/docs/0.5.0/api/ferroui-controls/visual_state/trait-visualstatemanagerimpl/)

## Availability

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