Skip to content

Class ViewState

Definition

Namespace: StardewUI.Framework.Behaviors
Assembly: StardewUI.dll

View state manager based on the view's runtime descriptor and defaults.

public class ViewState : StardewUI.Framework.Behaviors.IViewState

Inheritance
Object ⇦ ViewState

Implements
IViewState

Members

Constructors

Name Description
ViewState(IViewDescriptor, IViewDefaults, ViewState) View state manager based on the view's runtime descriptor and defaults.

Methods

Name Description
GetDefaultValue<T>(string) Retrieves the default value for a given property.
GetFlag<T>(string) Gets the current value of a flag, if one is set.
GetOrAddProperty<T>(string) Gets the override states for the specified property, creating a new one if it does not already exist.
GetProperty<T>(string) Gets the override states for the specified property, if any exist.
SetFlag(string, Object) Sets an arbitrary flag that other behaviors can read and/or be notified about.
Write(IView) Writes the active overrides to the target view.

Events

Name Description
FlagChanged Event raised when a flag changes, i.e. as the outcome of SetFlag(string, Object).

Details

Constructors

ViewState(IViewDescriptor, IViewDefaults, ViewState)

View state manager based on the view's runtime descriptor and defaults.

public ViewState(StardewUI.Framework.Descriptors.IViewDescriptor viewDescriptor, StardewUI.Framework.Descriptors.IViewDefaults viewDefaults, StardewUI.Framework.Behaviors.ViewState previousState);
Parameters

viewDescriptor   IViewDescriptor
Descriptor for the managed view type, providing property accessors.

viewDefaults   IViewDefaults
Default values for the managed view type.

previousState   ViewState
The previous state from which to restore the transient property values.


Methods

GetDefaultValue<T>(string)

Retrieves the default value for a given property.

public T GetDefaultValue<T>(string propertyName);
Parameters

propertyName   string
The property name.

Returns

T

The default value for the specified propertyName.

Remarks

The default value is the value that will be used when there are no states for that property, i.e. when GetProperty<T>(string) returns null for the specified propertyName or when the property's states are empty.

Defaults are real-time; if the property is linked via data binding, then the default value is the value that is currently bound.


GetFlag<T>(string)

Gets the current value of a flag, if one is set.

public T GetFlag<T>(string name);
Parameters

name   string
The flag name.

Returns

T

The flag value, or the default of T if not set.


GetOrAddProperty<T>(string)

Gets the override states for the specified property, creating a new one if it does not already exist.

public StardewUI.Framework.Behaviors.IPropertyStates<T> GetOrAddProperty<T>(string propertyName);
Parameters

propertyName   string
The property name.

Returns

IPropertyStates<T>

The state overrides for the specified property on the current view.


GetProperty<T>(string)

Gets the override states for the specified property, if any exist.

public StardewUI.Framework.Behaviors.IPropertyStates<T> GetProperty<T>(string propertyName);
Parameters

propertyName   string
The property name.

Returns

IPropertyStates<T>

The state overrides for the specified property, or null if none have been added.


SetFlag(string, Object)

Sets an arbitrary flag that other behaviors can read and/or be notified about.

public void SetFlag(string name, System.Object value);
Parameters

name   string
The flag name.

value   Object
The flag value, or null to unset.


Write(IView)

Writes the active overrides to the target view.

public void Write(StardewUI.IView view);
Parameters

view   IView
The view that should receive the state/overrides.


Events

FlagChanged

Event raised when a flag changes, i.e. as the outcome of SetFlag(string, Object).

public event EventHandler<StardewUI.Framework.Behaviors.FlagEventArgs>? FlagChanged;
Event Type

EventHandler<FlagEventArgs>