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

       声明非持久性类,对其应用域组件属性,并添加对象键属性。

    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).
    本例中省略了INotifyPropertyChanged、IXafEntityObject和IObjectSpaceLink接口实现。但是,建议在实际应用程序中支持这些接口(请参阅业务类和非持久性对象中的属性更改事件)。

    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.

    运行模块项目的模型编辑器并添加新的导航项。请注意,移动应用程序仅显示默认导航组内容。将 IModel 导航项.View 属性设置为要显示的详细信息视图的标识符(例如,NonPersistentObject_DetailView)。将 IModel 导航项.ObjectKey 属性设置为任意整数值。请注意,如果要显示此类型的不同非持久性对象,此值应是唯一的。

    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.

    在 C#/VB 编辑器中打开WinApplication.cs (WinApplication.vb)、WebApplication.cs(WebApplication.vb)和/或MobileApplication.cs(移动应用程序.vb)文件。确保非持久对象空间提供程序已注册在重写的创建默认对象空间提供程序方法(除了现有的 XPObjectSpace 提供程序或 EFObjectSpace 提供程序)。解决方案向导会自动添加此代码。请注意,如果您在较旧的 XAF 版本中创建项目,则此代码可能丢失。

    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.

       创建一个窗口控制器后代并处理非持久对象空间.ObjectByKey获取事件。在事件处理程序中,获取预定义的非持久性对象的实例,该实例上一步中指定了一个键。

    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:

    要为每个详细视图创建新的非持久对象,请使 ObjectKey 值在上一步中为空,并创建以下视图控制器:

    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.

    此控制器使用默认对象的构造函数创建新实例。还可以将参数传递给 CreateInstance(Object_)方法以使用另一个构造函数。

     

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

     

    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:

    • use the CreateObjectSpace(Type) method to create an Object Space for the non-persistent type;
    • use the XafApplication.CreateDetailView method to create a Detail View for the non-persistent type;
    • set the CustomizePopupWindowParamsEventArgs.View property to this Detail View.

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

     

    1.实施弹出窗口显示操作操作。
    2.处理其弹出窗口窗口显示操作.自定义弹出窗口窗口参数事件。
    3.In事件处理程序:

    • 使用 CreateObjectSpace(类型)方法为非持久性类型创建对象空间;
    • 使用 XafApplication.Create 详细信息视图方法为非持久性类型创建详细信息视图;
    • 将"自定义弹出窗口"ParamsEventArgs.View 属性设置为此详细信息视图。

    有关详细信息和示例,请参阅显示视图的方法和显示确认对话框主题的方法。

    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属性,如"如何:使用操作属性创建操作"主题中所示。

  • 相关阅读:
    nodejs express hi-cms
    写让别人能读懂的代码
    统计学和数据挖掘的关系
    假设检验
    相关性探索
    领域驱动设计分层类图
    未能加载文件或程序集 Ninject.Web.Common, Version=3.2.0.0
    论文阅读笔记
    《Computational Statistics with Matlab》硬译2
    C#抽象类和接口
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Display-a-Non-Persistent-Object-s-Detail-View.html
Copyright © 2020-2023  润新知