All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Initialize Business Object Properties (XPO)

  • 2 minutes to read

This lesson explains how to initialize properties in newly created business objects.

For this purpose, you will add the Priority property to the DemoTask class created in the Set a Many-to-Many Relationship (XPO) lesson. Then you will override the AfterConstruction method to initialize the new property.

NOTE

Before you proceed, take a moment to review the previous lessons:

Step-by-Step Instructions

  1. Add the Priority property to the DemoTask class and declare the Priority enumeration, as shown below:

    public class DemoTask : Task {
        // ...
        private Priority priority;
        public Priority Priority {
            get { return priority; }
            set {
                SetPropertyValue(nameof(Priority), ref priority, value);
            }
        }
        //...
    }
    public enum Priority {
        Low,
        Normal,
        High
    }
    
  2. To initialize the newly added Priority property when a DemoTask object is created, override the AfterConstruction method, as shown below:

    [DefaultClassOptions]
    [ModelDefault("Caption", "Task")]
    public class DemoTask : Task {
        //...
        public override void AfterConstruction() {
            base.AfterConstruction();
            Priority = Priority.Normal;
        }
        //...
    }
    
  3. Run the application.

    Create a new DemoTask object. In the Task detail view, the Priority property is set to Priority.Normal, as declared in the code above.

    xaf blazor nitialize property value

    Note that XAF generates a combo box for the Priority property. The combo box items are the enumeration values declared in the step 2.

Detailed Explanation

Initialize Property Values

The AfterConstruction method is executed when a new business object is created. In this tutorial, you override this method to set the Priority property to Priority.Normal when a new DemoTask object is created.

Next Lesson

Implement Dependent Reference Properties (XPO)

See Also