# ViewModelBase

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-diagnostics/diagnostics/view_models/struct-viewmodelbase/

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

```rust
struct ViewModelBase
```

The base of the view models of the developer tools: the property change
notification and the helpers that raise it.

A view model embeds it (the base class of the original) and forwards
`INotifyPropertyChanged` to it. The name of the property is passed
explicitly where the original takes the name of the calling member.

The original also records every addition and removal of a handler in a
list that nothing reads; the port leaves that list out.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L17)

## Members

- [`new`](#function-new)
- [`set_on_property_changed`](#function-set_on_property_changed)
- [`raise_and_set_if_changed`](#function-raise_and_set_if_changed)
- [`raise_and_set_if_changed_cell`](#function-raise_and_set_if_changed_cell)
- [`raise_property_changed`](#function-raise_property_changed)

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

### new

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L29)

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

### set_on_property_changed

```rust
fn set_on_property_changed(self: &Self, handler: Option<Rc<dyn Fn(&str) -> ()>>)
```

The override of `protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)`
of a deriving view model: called with the name of the property before
the handlers of `property_changed`.
The base implementation does nothing. A deriving view model sets it
once, when it is constructed (a closure over a weak reference to
itself).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L39)

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

### raise_and_set_if_changed

```rust
fn raise_and_set_if_changed<T: PartialEq>(self: &Self, field: &RefCell<T>, value: T, property_name: &str) -> bool
```

`RaiseAndSetIfChanged(ref field, value)` for a field of a type that is
not `Copy`: stores `value` and raises the notification of
`property_name` when it differs from the stored value. Returns whether
it did.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L47)

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

### raise_and_set_if_changed_cell

```rust
fn raise_and_set_if_changed_cell<T: PartialEq + Copy>(self: &Self, field: &Cell<T>, value: T, property_name: &str) -> bool
```

`RaiseAndSetIfChanged(ref field, value)` for a `Copy` field.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L59)

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

### raise_property_changed

```rust
fn raise_property_changed(self: &Self, property_name: &str)
```

`RaisePropertyChanged(propertyName)`: the override of
`OnPropertyChanged`, then the handlers.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Diagnostics/diagnostics/view_models/view_model_base.rs#L71)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- `Default`
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)

## Availability

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