Skip to content

Class VisibilityStateBehavior<TValue>

Definition

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

Behavior that applies a property override when a view enters or leaves the visible state.

public class VisibilityStateBehavior<TValue> : 
    StardewUI.Framework.Behaviors.ViewBehavior<TView, TData>

Type Parameters

TValue
Value type for the overridden property.

Inheritance
ObjectViewBehavior<TView, TData> ⇦ VisibilityStateBehavior<TValue>

Remarks

The override is added when the view's Visibility becomes StardewUI.Layout.Visibility.#ctor and removed when it becomes Hidden. In addition, the state corresponding to the view's initial visibility is applied as soon as the behavior as initialized, allowing for transitions to occur when the view is first created even if the visibility never explicitly changes.

Members

Constructors

Name Description
VisibilityStateBehavior<TValue>(string) Behavior that applies a property override when a view enters or leaves the visible state.

Properties

Name Description
Data The assigned or bound data.
(Inherited from ViewBehavior<TView, TData>)
View The currently-attached view.
(Inherited from ViewBehavior<TView, TData>)
ViewState State overrides for the View.
(Inherited from ViewBehavior<TView, TData>)

Methods

Name Description
CanUpdate() Checks whether the behavior is allowed to Update(TimeSpan).
(Inherited from ViewBehavior<TView, TData>)
Dispose() (Inherited from ViewBehavior<TView, TData>)
Initialize(BehaviorTarget) Initializes the target (view, state overrides, etc.) for the behavior.
(Inherited from ViewBehavior<TView, TData>)
OnAttached() Runs after the behavior is attached to a target.
(Overrides ViewBehavior<TView, TData>.OnAttached())
OnDetached(IView) Runs when the behavior is detached from a target.
(Overrides ViewBehavior<TView, TData>.OnDetached(IView))
OnDispose() Runs when the behavior is being disposed.
(Inherited from ViewBehavior<TView, TData>)
OnNewData(TValue) (Overrides ViewBehavior<TView, TData>.OnNewData(TData))
PreUpdate(TimeSpan) Runs on every update tick, before any bindings or views update.
(Inherited from ViewBehavior<TView, TData>)
Update(TimeSpan) Runs on every update tick.
(Overrides ViewBehavior<TView, TData>.Update(TimeSpan))

Details

Constructors

VisibilityStateBehavior<TValue>(string)

Behavior that applies a property override when a view enters or leaves the visible state.

public VisibilityStateBehavior<TValue>(string propertyName);
Parameters

propertyName   string
Name of the overridden property.

Remarks

The override is added when the view's Visibility becomes StardewUI.Layout.Visibility.#ctor and removed when it becomes Hidden. In addition, the state corresponding to the view's initial visibility is applied as soon as the behavior as initialized, allowing for transitions to occur when the view is first created even if the visibility never explicitly changes.


Methods

OnAttached()

Runs after the behavior is attached to a target.

protected override void OnAttached();
Remarks

Setup code should go in this method to ensure that the values of View and ViewState are actually assigned. If code runs in the behavior's constructor, these are not guaranteed to be populated.


OnDetached(IView)

Runs when the behavior is detached from a target.

protected override void OnDetached(StardewUI.IView view);
Parameters

view   IView
The view that was previously attached.

Remarks

Behaviors may receive new views as part of a "rebind", if the old view is destroyed and recreated, for example as the result of a conditional binding changing states.

OnDetached is always immediately followed by OnAttached(). A behavior cannot remain in a detached state; however, overriding this method gives behaviors the opportunity to clean up state from the old view (e.g. remove event handlers) before the new one is attached.

Also runs when the behavior is disposed, so detach logic does not need to be duplicated in OnDispose().


OnNewData(TValue)

protected override void OnNewData(TValue previousData);
Parameters

previousData   TValue


Update(TimeSpan)

Runs on every update tick.

public override void Update(System.TimeSpan elapsed);
Parameters

elapsed   TimeSpan
Time elapsed since the last update.