Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to enable/disable property-bound controls
xomega
#1 Posted : Friday, October 12, 2012 5:47:07 PM(UTC)
xomega



When you bind WPF, Silverlight or web controls on your form to Xomega data properties, both their state and value(s) will be in sync with those of the data property. This means that the control will be enabled or disabled based on whether or not the underlying data property is editable.

This allows you to set the properties as editable or not editable in your view model, which will be automatically reflected by the control, rather than working with the control itself. Generally, you would set editability of individual data properties in your data object either during initialization, or in response to a change in another data property or data object as follows.
Code:
public partial class EmployeeObject
{
    protected override void OnInitialized()
    {
        // modification date is never editable
        ModifiedDateProperty.Editable = false;

        // update state of other properties now and whenever current flag changes
        UpdateCurrentState(null, new PropertyChangeEventArgs(PropertyChange.All, null, null));
        CurrentFlagProperty.Change += UpdateCurrentState;
    }

    void UpdateCurrentState(object sender, PropertyChangeEventArgs e)
    {
        if (!e.Change.IncludesValue()) return;

        // vacation and sick hours are editable only on current employees
        bool? isCurrent = CurrentFlagProperty.Value ?? false;
        VacationHoursProperty.Editable = !isCurrent.Value;
        SickLeaveHoursProperty.Editable = !isCurrent.Value;
    }
}


Another powerful feature that Xomega Framework provides is the ability to make the whole data object not editable, which would automatically disable all of its properties and child objects and the controls that are bound to them as a result. If you then set the data object back to being editable, all of its properties will become either editable or not editable as configured on the individual property level. This is useful when you want to support a form in both read-only mode and an edit mode, which you would toggle by clicking an Edit button and then turn off upon saving as follows.
Code:
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
    objEmployee.Editable = true;
    // lock the form/object to prevent other users from editing the object
}

private void btnSave_Click(object sender, RoutedEventArgs e)
{
    // do the validation and save, release the lock
    objEmployee.Editable = false;
}
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.