Click or drag to resize

PropertyStoreSetT Method (Object, T, Action, T)

Set the value for the specified property key, calling the propertyChanged delegate if it has changed.

Namespace:  Eto
Assembly:  Eto (in Eto.dll) Version: 2.5.3-dev
Syntax
public bool Set<T>(
	Object key,
	T value,
	Action propertyChanged,
	T defaultValue = null
)

Parameters

key
Type: SystemObject
Key of the property to set.
value
Type: T
Value for the property.
propertyChanged
Type: SystemAction
Property changed event handler to raise if the property value has changed.
defaultValue (Optional)
Type: T
Default value of the property to compare when removing the key

Type Parameters

T
The type of the property to set.

Return Value

Type: Boolean
true if the property was changed, false if not
Remarks
This is useful when creating properties that need to trigger changed events without having to write boilerplate code.
Examples
public class MyForm : Form
{
    static readonly MyPropertyKey = new object();

    public bool MyProperty
    {
        get { return Properties.Get<bool>(MyPropertyKey); }
        set { Properties.Set(MyPropertyKey, value, OnMyPropertyChanged); }
    }

    public event EventHandler<EventArgs> MyPropertyChanged;

    protected virtual void MyPropertyChanged(EventArgs e)
    {
        if (MyPropertyChanged != null)
            MyPropertyChanged(this, e);
    }
}
See Also