学习011-04-02 How to: Display a Non-Persistent Object‘s Detail View(如何:显示非持久化对象的详细视图)

How to: Display a Non-Persistent Object’s Detail View(如何:显示非持久化对象的详细视图)

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.
声明一个非持久类,对其应用DomainComponentAttribute,并添加一个对象键属性。

C#
using System.ComponentModel;
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 The Importance of Property Change Notifications for Automatic UI Updates and Non-Persistent Objects).
本示例中省略了INotifyPropertyChanged、IXafEntityObject和IObjectSpaceLink接口实现。但是,建议在实际应用程序中支持这些接口(请参阅自动UI更新和非持久性对象的属性更改通知的重要性)。

2.Rebuild the solution.
重建解决方案。

3.Run the Model Editor for a module project and add a new navigation item. Set the IModelNavigationItem.View property to the identifier of the Detail View to be displayed (for example, 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.
为模块项目运行模型编辑器并添加新的导航项。将IModelNavigationItem. View属性设置为要显示的详细信息视图的标识符(例如,NonPersistentObject_DetailView)。将IModelNavigationItem.ObjectKey属性设置为任意整数值。请注意,如果要显示此类型的不同非持久性对象,此值应是唯一的。
在这里插入图片描述

4.Open the WinApplication.cs , WebApplication.cs, and/or BlazorApplication.cs file in a C# 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.
在C#编辑器中打开WinApplication. cs、WebApplication.cs和/或BlazorApplication.cs文件。确保NonPersistentObjectSpaceProvider已在覆盖的CreateDefaultObjectSpaceProvider方法中注册(除了现有的XPObjectSpaceProvider或EFObjectSpaceProvider)。解决方案向导会自动添加此代码。请注意,如果您在较旧的XAF版本中创建项目,此代码可能会丢失。

C#
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
    // ...
    args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
}

5.Subscribe to the XafApplication.ObjectSpaceCreated event and, in its handler, subscribe to the NonPersistentObjectSpace.ObjectByKeyGetting event. In the ObjectByKeyGetting event handler, check if the requested object type is NonPersistentObject. If so, pass a NonPersistentObject instance with a key specified at step 3 as the e.Object event parameter.
订阅XafApplication. ObjectSpaceCreated事件,并在其处理程序中订阅NonPersistentObjectSpace.ObjectByKeyGet事件。在ObjectByKeyGet事件处理程序中,检查请求的对象类型是否为非持久性对象。如果是,则传递一个非持久性对象实例,该实例具有在步骤3中指定的键作为e.Object事件参数。

C#
using System;
using DevExpress.ExpressApp;
// ...
public sealed partial class MyModule : ModuleBase {
    //...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        application.SetupComplete += Application_SetupComplete;
    }
    private void Application_SetupComplete(object sender, EventArgs e) {
        Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
    }
    private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e) {
        var nonPersistentObjectSpace = e.ObjectSpace as NonPersistentObjectSpace;
        if(nonPersistentObjectSpace != null) {
            nonPersistentObjectSpace.ObjectByKeyGetting += nonPersistentObjectSpace_ObjectByKeyGetting;
        }
    }
    private void nonPersistentObjectSpace_ObjectByKeyGetting(object sender, ObjectByKeyGettingEventArgs e) {
        IObjectSpace objectSpace = (IObjectSpace)sender;
        if(e.ObjectType.IsAssignableFrom(typeof(NonPersistentObject))) {
            if(((int)e.Key) == 138) {
                NonPersistentObject obj138 = objectSpace.CreateObject<NonPersistentObject>();
                obj138.Oid = 138;
                obj138.Name = "Sample Object";
                e.Object = obj138;
            }
        }
    }
}

To create a new non-persistent object for each Detail View, leave the ObjectKey value empty in the Model Editor and create the following View Controller instead of the code above:
要为每个详细信息视图创建一个新的非持久对象,请在模型编辑器中将ObjectKey值留空并创建以下视图控制器而不是上面的代码:

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

When you use the CreateObject(Type) method to create an object, the Object Space considers this object as new. In this case, the Save confirmation dialog is displayed when you close the object View. If you do not want to show this dialog, call the NonPersistentObjectSpace.RemoveFromModifiedObjects method that marks this object as existing and not changed.
使用CreateObject(Type)方法创建对象时,对象空间将此对象视为新对象。在这种情况下,关闭对象视图时将显示保存确认对话框。如果不想显示此对话框,请调用NonPersistentObjectSpace.RemoveFromModifiedObjects方法,将此对象标记为现有且未更改。

The NonPersistentObjectSpace.CreateObject method uses the default constructor to create an object within the Object Space. If you want to use another constructor, create a new object and add it to the Object Space manually. For this purpose, pass this object to the NonPersistentObjectSpace.GetObject method. This allows the Object Space to track changes made to the new object (if it implements the INotifyPropertyChanged interface and the AutoSetModifiedOnObjectChange option is enabled).
NonPersistentObjectSpaceCreateObject方法使用默认构造函数在对象空间内创建对象。如果要使用另一个构造函数,创建一个新对象并手动将其添加到对象空间。为此,将此对象传递给NonPersistentObjectSpaceGetObject方法。这允许对象空间跟踪对新对象所做的更改(如果它实现了INotifyPropertyChanged接口并且启用了AutoSetModifiedOnObjectChange选项)。

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.
要在DashboardView中显示非持久性对象,请按照上一节中的步骤创建仪表板项而不是导航项。有关详细信息视图如何绑定到仪表板视图项的信息,请参阅DashboardView类描述。

Show a Non-Persistent Object in a Modal Dialog Window(在模态对话框窗口中显示非持久对象)

1.Implement a PopupWindowShowAction Action.
实施PopupWindowShowAction行动。

2.Handle its PopupWindowShowAction.CustomizePopupWindowParams event.
处理它的PopupWindowShowAction。CustomizePopupWindowParams事件。

3.In the event handler:
在事件处理程序中:

  • use the CreateObjectSpace(Type) method to create an Object Space for the non-persistent type;
    使用CreateObjectSpace(Type)方法为非持久类型创建对象空间;
  • use the XafApplication.CreateDetailView method to create a Detail View for the non-persistent type;
    使用XafApplication. CreateDetailView方法为非持久类型创建详细信息视图;
  • set the CustomizePopupWindowParamsEventArgs.View property to this Detail View.
    将CustomizePopupWindowParamsEventArgs. View属性设置为详细信息视图。

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.
要执行简单的业务逻辑并提示用户输入参数,请使用如何:使用操作属性创建操作主题中所示的Action属性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值