Skip to content

Class ContextPropertyValueSource<T>

Definition

Namespace: StardewUI.Framework.Sources
Assembly: StardewUI.dll

Value source that obtains its value from a context (or "model") property.

public class ContextPropertyValueSource<T> : 
    StardewUI.Framework.Sources.IValueSource<T>, 
    StardewUI.Framework.Sources.IValueSource, System.IDisposable

Type Parameters

T
The return type of the context property.

Inheritance
Object ⇦ ContextPropertyValueSource<T>

Implements
IValueSource<T>, IValueSource, IDisposable

Members

Constructors

Name Description
ContextPropertyValueSource<T>(BindingContext, string, Boolean) Initializes a new instance of ContextPropertyValueSource<T> using the specified context and property name.

Properties

Name Description
CanRead Whether or not the source can be read from, i.e. if an attempt to get the Value should succeed.
CanWrite Whether or not the source can be written back to, i.e. if an attempt to set the Value should succeed.
DisplayName Descriptive name for the property, used primarily for debug views and log/exception messages.
Value
ValueType The compile-time type of the value tracked by this source; the type parameter for IValueSource<T>.

Methods

Name Description
Dispose()
Update(Boolean) Checks if the value needs updating, and if so, updates Value to the latest.

Details

Constructors

ContextPropertyValueSource<T>(BindingContext, string, bool)

Initializes a new instance of ContextPropertyValueSource<T> using the specified context and property name.

public ContextPropertyValueSource<T>(StardewUI.Framework.Binding.BindingContext context, string propertyName, bool allowUpdates);
Parameters

context   BindingContext
Context used for the data binding.

propertyName   string
Property to read on the Data of the supplied context when updating.

allowUpdates   Boolean
Whether or not to allow Update(Boolean) to read a new value. false prevents all updates and makes the source read only one time.

Remarks

If the Data of the supplied context implements INotifyPropertyChanged, then Update(Boolean) and Value will respond to changes to the given propertyName. Otherwise, the source is "static" and will never change its value or return true from Update(Boolean).


Properties

CanRead

Whether or not the source can be read from, i.e. if an attempt to get the Value should succeed.

public bool CanRead { get; }
Property Value

Boolean


CanWrite

Whether or not the source can be written back to, i.e. if an attempt to set the Value should succeed.

public bool CanWrite { get; }
Property Value

Boolean


DisplayName

Descriptive name for the property, used primarily for debug views and log/exception messages.

public string DisplayName { get; }
Property Value

string


Value

public T Value { get; set; }
Property Value

T


ValueType

The compile-time type of the value tracked by this source; the type parameter for IValueSource<T>.

public System.Type ValueType { get; }
Property Value

Type


Methods

Dispose()

public void Dispose();

Update(bool)

Checks if the value needs updating, and if so, updates Value to the latest.

public bool Update(bool force);
Parameters

force   Boolean
If true, forces the source to update its value even if it isn't considered dirty. This should never be used in a regular binding, but can be useful in sources that are intended for occasional or one-shot use such as event handler arguments.

Returns

Boolean

true if the Value was updated; false if it already held the most recent value.

Remarks

This method is called every frame, for every binding, and providing a correct return value is essential in order to avoid slowdowns due to unnecessary rebinds.