Ticket Q310354
Visible to All Users

How to apply a Conditional Appearance rule only to new or saved objects

created 14 years ago

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

Answers approved by DevExpress Support

created 14 years ago (modified 5 years ago)

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.

    Show previous comments (3)

      It's a method in the class that defines the persistent object.
      Cheers, Paul.

      Dennis Garavsky (DevExpress) 10 years ago

        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.

        DevExpress Support Team 5 years ago

          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.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.