How to: Display a Non-Persistent Object's List View from the 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.

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

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

    For simplicity, implementation of the INotifyPropertyChangedIXafEntityObject and IObjectSpaceLink interfaces are 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).

  • Open the WinApplication.cs (WinApplication.vb) and/or WebApplication.cs (WebApplication.vb) code. Ensure that the NonPersistentObjectSpaceProvider is registered in the overriddenCreateDefaultObjectSpaceProvider method (in addition to the existing XPObjectSpaceProvider or EFObjectSpaceProvider). Currently, this code is added automatically by the Solution Wizard, but it may be missing if you have created your project using an older version of XAF.

    C#
    VB
     
    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.

  • 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.

    C#
    VB
     
    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

    You can also use the e.Sorting and e.Criteria arguments of the ObjectsGetting event to access sorting and filtering, respectively.

The result is demonstrated in the image below.

Tip

The NewDelete and Save Actions are available for non-persistent objects. To access all created, deleted and modified objects within NonPersistentObjectSpace, use the NonPersistentObjectSpace.ModifiedObjects property.

 

 

Expanded See Also

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 How to cast List to List Object集合轉換成實體集合 Android - Bottom Navigation View Exception loading sessions from persistent storage 這個問題的解決 List mysql 創建視圖出現1349 View's SELECT contains a subquery in the FROM clause解決辦法 how to stop MongoDB from the command line MobaXterm以圖形界面GUI形式登錄打開遠程linux ubuntu服務器桌面; How can I display a full remote desktop from a Unix/Linux server in MobaXterm; Forward Linux X11 Session to Windows [UE4]List View Navigation 實現不同fragment之間的view的共享(含動畫過渡) 解決"Uncaught (in promise) Error: Navigation cancelled from "/" to "/login" with a new navigation"報錯處理
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM