Hello DevExpress,
Can I use the Conditional Appearance attribute to only allow a property to be editable in the UI when it's being created (New) and at all other times the editor for the property is disabled - i.e. visible but not editable ?
Cheers,
Paul
How to apply a Conditional Appearance rule only to new or saved objects
Answers approved by DevExpress Support
Hello Paul,
Starting with version 14.1.6, XAF provides the IsNewObject function for XPO classes. Here is an example of how to use it in a Conditional Appearance rule:
C#[Appearance("HideNickName", AppearanceItemType = "LayoutItem", Visibility = ViewItemVisibility.Hide, TargetItems = "NickName", Context = "DetailView", Criteria = "This is not null and IsNewObject(This)")]
public class DomainObject1 : BaseObject {
See Function Criteria Operators for details.
In previous versions, you can implement this using the Session.IsNewObject method. Here is the sample code:
C#[Appearance("DisableName", AppearanceItemType="ViewItem", Context="DetailView", Enabled=false, TargetItems="Name")]
protected bool IsNotNew() {
return !Session.IsNewObject(this);
}
In v20.1, the IsNewObject function (IsNewObjectCriteriaOperator) works both for XPO persistent objects and for objects that implement the [IObjectSpaceLink][0] interface. This interface can be implemented in Entity Framework classes and Non-Persistent object classes.
BTW, in the latest XAF versions you no longer need this method as you can now use the built-in IsNewObject criteria function from Filtering - Create a built-in criteria function to check if an XPO object is new or saved.
In v20.1, the IsNewObject function (IsNewObjectCriteriaOperator) works both for XPO persistent objects and for objects that implement the IObjectSpaceLink interface. This interface can be implemented in Entity Framework classes and Non-Persistent object classes.