Skip to main content
A newer version of this page is available. .

How to: Display a Non-Persistent Object's Detail View

  • 5 minutes to read

Show a Non-Persistent Object from the Navigation

  1. Declare a non-persistent class, apply the DomainComponentAttribute to it, and add an object key property.

    using DevExpress.ExpressApp.DC;
    // ...
    [DomainComponent]
    public class NonPersistentObject {
        [Browsable(false)]
        [DevExpress.ExpressApp.Data.Key]
        public int Oid { get; set; }
        public string Name { get; set; }
    }
    

    Note

    The INotifyPropertyChanged, IXafEntityObject and IObjectSpaceLink interface implementations were omitted in this example. However, it is recommended to support these interfaces in real-world applications (see PropertyChanged Event in Business Classes and Non-Persistent Objects).

  2. Rebuild the solution.
  3. Run the Model Editor for a module project and add a new navigation item. Note that Mobile applications show only the Default navigation group content. Set the IModelNavigationItem.View property to the identifier of the Detail View to be displayed (e.g., NonPersistentObject_DetailView). Set the IModelNavigationItem.ObjectKey property to an arbitrary integer value. Note that this value should be unique if you want to display different non-persistent objects of this type.

    NonPersistentKey

  4. Open the WinApplication.cs (WinApplication.vb), WebApplication.cs (WebApplication.vb), and/or MobileApplication.cs (MobileApplication.vb) file in a C#/VB Editor. Ensure that the NonPersistentObjectSpaceProvider is registered in the overridden CreateDefaultObjectSpaceProvider method (in addition to the existing XPObjectSpaceProvider or EFObjectSpaceProvider). The Solution Wizard adds this code automatically. Note that this code may be missing if you created your project in an older XAF version.

    protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
        // ...
        args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
    }
    
  5. Create a WindowController descendant and handle the NonPersistentObjectSpace.ObjectByKeyGetting event. In the event handler, get an instance of the predefined non-persistent object with a key specified at the previous step.

    using DevExpress.ExpressApp;
    // ...
    public class NonPersistentObjectsController : WindowController {
        private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e) {
            NonPersistentObjectSpace nonPersistentObjectSpace = e.ObjectSpace as NonPersistentObjectSpace;
            if(nonPersistentObjectSpace != null) {
                nonPersistentObjectSpace.ObjectByKeyGetting += nonPersistentObjectSpace_ObjectByKeyGetting;
            }
        }
        private void nonPersistentObjectSpace_ObjectByKeyGetting(object sender, ObjectByKeyGettingEventArgs e) {
            if(e.ObjectType.IsAssignableFrom(typeof(NonPersistentObject))) {
                if(((int)e.Key) == 138) {
                    NonPersistentObject obj138 = new NonPersistentObject();
                    obj138.Key = 138;
                    obj138.Name = "Sample Object";
                    e.Object = obj138;
                }
            }
        }
        protected override void OnActivated() {
            base.OnActivated();
            Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
        }
        protected override void OnDeactivated() {
            base.OnDeactivated();
            Application.ObjectSpaceCreated -= Application_ObjectSpaceCreated;
        }
        public NonPersistentObjectsController() {
            TargetWindowType = WindowType.Main;
        }
    }
    

    To create a new non-persistent object for each Detail View, leave the ObjectKey value empty at the previous step and create the following View Controller:

    using DevExpress.ExpressApp;
    // ...
    public class NonPersistentObjectActivatorController : ObjectViewController<DetailView, NonPersistentObject> {
        protected override void OnActivated() {
            base.OnActivated();
            if ((ObjectSpace is NonPersistentObjectSpace) && (View.CurrentObject == null)) {
                View.CurrentObject = View.ObjectTypeInfo.CreateInstance();
                View.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
            }
        }
    }
    

    This Controller uses the default object’s constructor to create a new instance. You can also pass arguments to the CreateInstance(Object[]) method to use another constructor.

Show Non-Persistent Objects in a Dashboard View

To show non-persistent objects in a DashboardView, follow the steps from the previous section and create a dashboard item instead of the navigation item. Refer to the DashboardView class description for information on how a Detail View binds to a Dashboard View item.

Show a Non-Persistent Object in a Modal Dialog Window

  1. Implement a PopupWindowShowAction Action.
  2. Handle its PopupWindowShowAction.CustomizePopupWindowParams event.
  3. In the event handler:

Refer to the Ways to Show a View and Ways to Show a Confirmation Dialog topics for more information and examples.

Show a Non-Persistent Dialog from a Business Class

To execute simple business logic and prompt a user for parameters, use the ActionAttribute as shown in the How to: Create an Action Using the Action Attribute topic.

See Also