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 visible on the screen based on whether or not the underlying data property is visible and the user has at least read-only access to it.
This allows you to set the visibility and access level for properties and their data objects in your view model, which will be automatically reflected by the controls, rather than hiding or showing the control itself. Generally, you would set the access level on the data object or individual data properties during initialization based on the privileges of the current user. The property visibility, however, could be set in response to a change in another data property or data object.
The following example demonstrates how access level is set on the employee's National ID Number Property during initialization and the Spouse Name Property is made visible only if the marital status is not single.
Code:
public partial class EmployeeObject
{
protected override void OnInitialized()
{
// make SSN editable for HR users, visible to directors and hidden to others
NationalIDNumberProperty.AccessLevel = IsHR() ? AccessLevel.Full ?
(IsDirector() ? AccessLevel.ReadOnly : AccessLevel.None);
// update visibility of the spouse property now and whenever marital status changes
UpdateSpouseProperty(null, new PropertyChangeEventArgs(PropertyChange.All, null, null));
MaritalStatusProperty.Change += UpdateSpouseProperty;
}
void UpdateSpouseProperty(object sender, PropertyChangeEventArgs e)
{
if (!e.Change.IncludesValue()) return;
// hide spouse name field for single employees
SpouseNameProperty.Visible = MaritalStatusProperty.Value != null &&
(MaritalStatusProperty.Value.Id != Enumerations.MaritalStatus.Single);
}
}