zoukankan      html  css  js  c++  java
  • How to:Create a New Object using the Navigation Control 如何:使用导航控件创建新对象

    This topic demonstrates how to execute custom code on a specific navigation item click. A navigation item that invokes the Detail View in Edit mode for an Issue object is added to the Navigation control.

    本主题演示如何在特定导航项单击上执行自定义代码。在"问题"对象的编辑模式下调用"详细信息视图"的导航项将添加到导航控件中。

    CreateObjectFromNavigationControl

    Tip 提示
    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E236
    完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E236

    .

    In this example, the following Issue persistent class is used for demo purposes. You can use any other persistent class.

    在此示例中,以下问题持久性类用于演示目的。您可以使用任何其他持久性类。

    using DevExpress.Persistent.Base;
    using DevExpress.Persistent.BaseImpl;
    using DevExpress.Xpo;
    // ...
    [DefaultClassOptions, ImageName("BO_List")]
    public class Issue : BaseObject {
        public Issue(Session session) : base(session) { }
        private string subject;
        public string Subject {
            get { return subject; }
            set { SetPropertyValue(nameof(Subject), ref subject, value); }
        }
        private string description;
        [Size(SizeAttribute.Unlimited)]
        public string Description {
            get { return description; }
            set { SetPropertyValue(nameof(Description), ref description, value); }
        }
    }

    To create a new object using the Navigation control, add a new navigation item and specify the code to be executed on this item click.

    要使用导航控件创建新对象,请添加新导航项并指定要在此项目单击上执行的代码。

    Add a new Navigation Item

    添加新导航项

    To add a new navigation item, invoke the Model Editor for the module project by double-clicking the Model.DesignedDiffs.xafml file. Find the Issue navigation item node and add a new node to the same navigation group.

    要添加新的导航项,请双击"模型.设计Diffs.xafml"文件来调用模块项目的模型编辑器。查找问题导航项节点并将新节点添加到同一导航组。

    For this node, specify the properties from the table below with the corresponding values:

    对于此节点,使用相应的值从下表中指定属性:

     

    PropertyValue
    IModelBaseChoiceActionItem.Id NewIssue
    IModelBaseChoiceActionItem.Caption Create New Issue...
    IModelBaseChoiceActionItem.ImageName Action_New
    IModelNavigationItem.View Issue_DetailView

     

    CreateObjectFromNavigationControl_ME

    Note 注意
    Do not set the StartupNavigationItem property to this navigation item for Mobile applications, because they do not support a Detail View displaying on an application start.
    不要将"启动导航项目"属性设置为移动应用程序的此导航项,因为它们不支持在应用程序启动时显示的详细信息视图。

    Refer to the Add an Item to the Navigation Control topic to learn more about creating navigation items in the Model Editor.

    请参阅将项目添加到导航控制主题,了解有关在模型编辑器中创建导航项的详细信息。

    Specify the Code to be Executed on a Navigation Item Click

    指定要在导航项目单击上执行的代码

    To specify the code to be executed when the Create New Issue... navigation item is clicked, follow the steps below:

    1.Create a Controller that is the WindowController descendant, override the OnActivated method, and subscribe to the ShowNavigationItemController.CustomShowNavigationItem event in this method. Use the Frame.GetController<ControllerType>

       method to access the ShowNavigationItemController instance.

    2.In the CustomShowNavigationItem event handler, access the current navigation item identifier using the CustomShowNavigationItemEventArgs.ActionArguments event argument.

    3.If the identifier is "NewIssue", create the following objects using the corresponding methods from the table below:

    Object

    Method
    Object Space XafApplication.CreateObjectSpace
    Issue object IObjectSpace.CreateObject
    Detail View for the Issue object XafApplication.CreateDetailView

     4.Set the Detail View's DetailView.ViewEditMode property to ViewEditMode.Edit and specify that this View should be displayed using the ShowViewParameters.CreatedView property.

    5.Since the Navigation control is displayed in the main Window only, the created Controller should be activated for the main Window as well by setting the WindowController.TargetWindowType property to Main in the Controller's constructor.

    要指定创建新问题时要执行的代码...单击导航项,请按照以下步骤操作:

    1.创建一个控制器,它是窗口控制器的后代,重写OnActivated方法,并订阅显示导航项目控制器.自定义导航项目事件此方法。使用帧.获取控制器<ControllerType>
       方法访问显示导航项目控制器实例。
    2.In自定义显示导航项目事件处理程序,使用自定义显示导航项目事件参数访问当前导航项标识符。
    3.如果标识符为"NewIssue",请使用下表中的相应方法创建以下对象:

    Object
    Method
    Object Space XafApplication.CreateObjectSpace
    Issue object IObjectSpace.CreateObject
    Detail View for the Issue object XafApplication.CreateDetailView

    4.将明细视图的明细视图.ViewEditMode 属性设置为"查看编辑模式",编辑并指定此视图应使用 ShowView 参数。"创建视图"属性显示此视图。
    5.由于导航控件仅显示在主窗口中,因此应在控制器的构造函数中设置 WindowControl.TargetWindowType 属性来激活主窗口的创建控制器。

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.SystemModule;
    // ...
    public class NewObjectFromNavigationController : WindowController {
        public NewObjectFromNavigationController() {
            TargetWindowType = WindowType.Main;
        }
        protected override void OnActivated() {
            base.OnActivated();
            ShowNavigationItemController showNavigationItemController = Frame.GetController<ShowNavigationItemController>();
            showNavigationItemController.CustomShowNavigationItem += showNavigationItemController_CustomShowNavigationItem;
        }
        void showNavigationItemController_CustomShowNavigationItem(object sender, CustomShowNavigationItemEventArgs e) {
            if (e.ActionArguments.SelectedChoiceActionItem.Id == "NewIssue") {
                IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Issue));
                Issue newIssue = objectSpace.CreateObject<Issue>();
                DetailView detailView = Application.CreateDetailView(objectSpace, newIssue);
                detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
                e.ActionArguments.ShowViewParameters.CreatedView = detailView;
                e.Handled = true;
            }
        }
    }

    Run the WinForms, ASP.NET or Mobile application to check that the Issue objects can be created using the Create New Issue... navigation item (see the image at the beginning of this topic).

    运行 WinForms、ASP.NET或移动应用程序,以检查是否可以使用"创建新问题"创建问题对象...导航项(请参阅本主题开头的图像)。

  • 相关阅读:
    easyui
    H+ Se7en WebUI
    WEB IM
    PowerDesigner 导出 Excel
    SSO跨域 CodeProject
    ICU 是一种说不出的痛啊
    C#的Main(String[] args)参数输入问题
    C# TabControl标签的隐藏
    在foreach的判断条件里执行方法会有效率问题吗?
    C#编程命名规范推荐
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Create-a-New-Object-using-the-Navigation-Control.html
Copyright © 2011-2022 走看看