Skip to content

Interface IViewBehavior

Definition

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

Provides methods for attaching arbitrary data-dependent behavior to a view.

public interface IViewBehavior : System.IDisposable

Implements
IDisposable

Remarks

Add-ons should normally not use this interface directly, and instead derive from ViewBehavior<TView, TData> for type safety.

Members

Properties

Name Description
DataType The type of data that the behavior accepts in SetData(Object).

Methods

Name Description
CanUpdate() Checks whether the behavior is allowed to Update(TimeSpan).
Initialize(BehaviorTarget) Initializes the target (view, state overrides, etc.) for the behavior.
PreUpdate(TimeSpan) Runs on every update tick, before any bindings or views update.
SetData(Object) Updates the behavior's current data.
Update(TimeSpan) Runs on every update tick.

Details

Properties

DataType

The type of data that the behavior accepts in SetData(Object).

System.Type DataType { get; }
Property Value

Type


Methods

CanUpdate()

Checks whether the behavior is allowed to Update(TimeSpan).

bool CanUpdate();
Returns

Boolean

true to continue running Update(TimeSpan) ticks, false to skip updates.

Remarks

Implementations can override this in order to selectively disable updates. Typically, updates will be disabled when the behavior cannot run due to not having an attached view or data.


Initialize(BehaviorTarget)

Initializes the target (view, state overrides, etc.) for the behavior.

void Initialize(StardewUI.Framework.Behaviors.BehaviorTarget target);
Parameters

target   BehaviorTarget
The target of the behavior.

Remarks

The framework guarantees that Update(TimeSpan) will never be called before Initialize, so views may be implemented with default parameterless constructors and perform initialization in this method.


PreUpdate(TimeSpan)

Runs on every update tick, before any bindings or views update.

void PreUpdate(System.TimeSpan elapsed);
Parameters

elapsed   TimeSpan

Remarks

Typically used to read information about the underlying view as it existed at the beginning of the frame, e.g. to handle a transition.


SetData(Object)

Updates the behavior's current data.

void SetData(System.Object data);
Parameters

data   Object
The new data.


Update(TimeSpan)

Runs on every update tick.

void Update(System.TimeSpan elapsed);
Parameters

elapsed   TimeSpan
Time elapsed since the last update.