How to: Display a Non-Persistent Object's List View from the Navigation How to: display a list of non-persistent objects from view navigation

This example demonstrates how to display a non-persistent object's List View when a navigation item is chosen. Note that this approach is compatible with the Client data access mode only.

This example shows how to display the list view non-persistent objects in the choice of navigation items. Note that this method is only compatible with the client data access patterns.

  • Declare a non-persistent class (e.g., MyNonPersistentObject), and decorate it with the DomainComponentAttribute and DefaultClassOptionsAttribute attributes.

  • Declared non-persistent type (for example, MyNon persistent objects), and use the domain component attributes and default options class Properties to modify it.

    using DevExpress.ExpressApp.DC;
    using DevExpress.Persistent.Base;
    // ...
    [DomainComponent, DefaultClassOptions]
    public class MyNonPersistentObject {
        // ...
    }

     

    Note 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).
    This example omitted INotifyPropertyChanged, IXafEntityObject and IObjectSpaceLink interface. However, it is recommended to support these interfaces in practical application (see Property change events business class and non-persistent objects)

 

  • 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.
  • Open WinApplication.cs (WinApplication.vb), WebApplication.cs (WebApplication.vb) and / or MobileApplication.cs (MobileApplication.vb) files in C # / VB editor. Ensure that non-persistent object space provider has registered provider method of rewriting create a default object space (in addition to the existing XPObjectSpace provider or EFObjectSpace provider). Solution Wizard will automatically add this code. Please note that if you create a project in XAF older versions, this code may be lost.
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
    // ...
    args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
}

If you now run the application, you will see that the My Non Persistent Object navigation item is created. It opens the List View which is empty, but you can create non-persistent objects with the New Action. If you reopen the List View, all created objects will, obviously, disappear.

If you now run the application, you will see the "My non-persistent object" navigation item has been created. It opens an empty list view, but you can use the "New Action" to create a non-persistent object. If you re-open a list view, all objects created obviously will disappear.

  • You can fill the List View programmatically. Create a Window Controller. In the overridden OnActivated method subscribe to the XafApplication.ListViewCreating event. In the event handler, if the Collection Source's object type is MyNonPersistentObject type, subscribe to the NonPersistentObjectSpace.ObjectsGetting event and populate the e.Objects collection as required.

  • You can populate the list view programmatically. Create a window controller. Subscribe Xaf applications rewritten On activated method .listView create an event. In the event handler, if the object type is a collection of source MyNon persistent object type, please subscribe to non-persistent object space .Objects get events, and a collection of the fill e.Objects needs.

using DevExpress.ExpressApp;
// ...
public class InitializeNonPersistentListViewWindowController : WindowController {
    public InitializeNonPersistentListViewWindowController() : base() {
        TargetWindowType = WindowType.Main;
    }
    protected override void OnActivated() {
        base.OnActivated();
        Application.ListViewCreating += Application_ListViewCreating;
    }
    private void Application_ListViewCreating(Object sender, ListViewCreatingEventArgs e) {
        if ((e.CollectionSource.ObjectTypeInfo.Type == typeof(MyNonPersistentObject)) && (e.CollectionSource.ObjectSpace is NonPersistentObjectSpace)) {
            ((NonPersistentObjectSpace)e.CollectionSource.ObjectSpace).ObjectsGetting += ObjectSpace_ObjectsGetting;
        }
    }
    private void ObjectSpace_ObjectsGetting(Object sender, ObjectsGettingEventArgs e) {
        BindingList<MyNonPersistentObject> objects = new BindingList<MyNonPersistentObject>();
        for (int i = 1; i < 10; i++) {
            objects.Add(new MyNonPersistentObject() { Name = string.Format("Object {0}", i) });
        }
        e.Objects = objects;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        Application.ListViewCreating -= Application_ListViewCreating;
    }
}

 

Tip Tip
  • You can also use the e.Sorting and e.Criteria arguments of the ObjectsGetting event to access sorting and filtering, respectively.In Mobile applications, the NonPersistentObjectSpace.ObjectByKeyGetting event should also be handled (see How to: Perform CRUD Operations with Non-Persistent Objects).
  • You can also use the "object to get" event e. E.Criteria sorting and filtering and sorting parameters are accessed.
  • In mobile applications, but also deal with non-persistent object space .ObjectByKey get events (see: How to perform CRUD operations on non-persistent objects).

The result is demonstrated in the image below.

Results are shown in FIG.

NonPersistentListViewInNavigation

Tip Tip
The New, Delete and Save Actions are available for non-persistent objects. To access all created, deleted and modified objects within NonPersistentObjectSpace, use the NonPersistentObjectSpace.ModifiedObjects property.
"New", "Delete" and "save operation" can be used for non-persistent objects. Object To access all non-persistent object space to create, delete, and modify, use the "non-persistent object space." Modify object "attribute.

Guess you like

Origin www.cnblogs.com/foreachlife/p/How-to-Display-a-Non-Persistent-Object-s-List-View-from-the-Navigation.html