See also:
- "How to pass PropertyCollectionSource as CollectionSource for PopupWindowShowAction" at http://www.devexpress.com/issue=CQ38893
- "How to display a list of non-persistent objects while retaining the possibility to 'add' new objects" at http://www.devexpress.com/issue=Q34001
- Core - Improve usability and support more scenarios of working with non-persistent objects
See Also:
WorldCreator module of eXpand
Creates dynamic persistent assemblies. The XAF user interface allows us to create an assembly without writing a single line of code. Advanced users can even use c# scripting and create new code generation templates.
Thanks,
Dan
Core - Provide an easy way to show a list of non-persistent objects created at runtime
Answers approved by DevExpress Support
We have implemented the functionality described in this ticket. It will be included in our next update(s).
Please check back and leave a comment to this response to let us know whether or not this solution addresses your concerns.
Now you can open a non-persistent object's List View from the Navigation using the following approach.
Declare a non-persistent class and decorate it with the DomainComponent and DefaultClassOptions attributes.
C#[DomainComponent, DefaultClassOptions]
public class MyNonPersistentObject {
// ...
}
Edit the WinApplication.cs/WebApplication code. In the overridden CreateDefaultObjectSpaceProvider method, register an extra Object Space Provider of the NonPersistentObjectSpaceProvider type (in addition to the existing XPObjectSpaceProvider or EFObjectSpaceProvider).
C#protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
// ...
args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
}
If you run the application now, 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. Edit the Module.cs file located in the module project. In the overridden Setup method subscribe to the XafApplication.ListViewCreating event. In the event handler, if the Collection Source's object type is MyNonPersistentObject, subscribe to the NonPersistentObjectSpace.ObjectsGetting event
and populate the e.Objects collection as required.
C#public sealed partial class MySolutionModule : ModuleBase {
// ...
public override void Setup(XafApplication application) {
base.Setup(application);
application.ListViewCreating += application_ListViewCreating;
}
void application_ListViewCreating(object sender, ListViewCreatingEventArgs e) {
if (e.CollectionSource.ObjectTypeInfo.Type == typeof(MyNonPersistentObject)) {
((NonPersistentObjectSpace)e.ObjectSpace).ObjectsGetting += objectSpace_ObjectsGetting;
}
}
void objectSpace_ObjectsGetting(object sender, ObjectsGettingEventArgs e) {
if (e.ObjectType == typeof(MyNonPersistentObject)) {
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;
e.Handled = true;
}
}
The result is demonstrated in the image below:
See also: How to: Display a Non-Persistent Object's List View from the Navigation
- v15.1.3Download Official Update
Thanks Dennis, for answering your own question :).
I think the reffered ticket shows promising features. Thank you!
Willem
@Willem: My new ticket just describes the most basic scenario that came to mind. So, I requested the information about concrete use-cases you and your clients were interested in to consider it for the future as well. If this basic scenario covers your needs, then there is no need to answer.