Add a Simple Action添加简单按钮

时间:2019-12-12 13:21:31   收藏:0   阅读:116

In this lesson, you will learn how to create a Simple Action. For this purpose, a new View Controller will be implemented and a new Simple Action will be added to it. This Action will clear all Tracked Tasks of a specific Contact.

在本课中,您将学习如何创建简单按钮。为此,将实施一个新的视图控制器,并将向其添加新的简单操作。此操作将清除特定联系人的所有跟踪任务。

Note 注意

Before proceeding, take a moment to review the following lessons.

  • Inherit from the Business Class Library Class (XPO/EF)
  • Implement Custom Business Classes and Reference Properties (XPO/EF)
  • Set a Many-to-Many Relationship (XPO/EF)

在继续之前,请花点时间复习以下课程。

  • 从商务舱库类 (XPO/EF) 继承
  • 实现自定义业务类和参考属性 (XPO/EF)
  • 设置多对多关系 (XPO/EF)

 

The View Controller is a descendant of the ViewController class. To add a View Controller that provides a Simple Action, follow the steps described below.

视图控制器是视图控制器类的后代。要添加提供简单操作的视图控制器,请按照以下步骤操作。

 

           XAF 控制器 |通过视图控制器可视化工作室模板,可以更轻松地向应用程序添加视图控制器。在"解决方案资源管理器"中,右键单击 MySolution.模块项目中的"控制器"文件夹,然后选择"添加开发人员快递项目"新项目...以调用模板库。然后选择"查看控制器",将"清除联系人任务控制器"指定为新项目的名称,然后单击"添加项目"。因此,您将获得一个自动生成的ClearContactTasksController.cs(ClearContact任务控制器.vb)文件,该文件带有单个视图控制器声明。

技术分享图片

  1. 技术分享图片

    Note 注意

    The same customization can be done in code, by setting the ViewController.TargetViewType property to ViewType.DetailView in the controller‘s constructor. If the property value is set after invoking the InitializeComponent method, the Designer setting will be overridden.

    通过在控制器的构造函数中设置 ViewTototoViewType 属性到 ViewType.detailView,可以在代码中执行相同的自定义。如果在调用初始化组件方法后设置了属性值,则将重写设计器设置。

     

    Alternatively, you can implement the generic ViewController<ViewType> Controller instead of the ViewController and specify the View‘s type, for which this Controller should be activated, in the ViewType generic parameter.

    或者,您可以在 ViewType 泛型参数中实现泛型视图控制器<ViewType>控制器,而不是视图控制器,并指定应为其激活此控制器的视图类型。

     

  2. Next, add SimpleAction to the ClearContactTasksController. In the DX.19.2: XAF Actions section in the Toolbox, drag SimpleAction to the Designer.

            接下来,将"简单操作"添加到清除联系人任务控制器。在工具箱中的 DX.19.2:XAF 操作部分中,将"简单操作"拖动到设计器。

技术分享图片

 

           实体框架

 

using MySolution.Module.BusinessObjects;
//...
private void ClearTasksAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
    ((Contact)View.CurrentObject).Tasks.Clear();
    ((DetailView)View).FindItem("Tasks").Refresh();
    ObjectSpace.SetModified(View.CurrentObject);
}

 

eXpress Persistent Objects

eXpress 持久对象

using MySolution.Module.BusinessObjects;
//...
private void ClearTasksAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
    while(((Contact)View.CurrentObject).Tasks.Count > 0) {
        ((Contact)View.CurrentObject).Tasks.Remove(((Contact)View.CurrentObject).Tasks[0]);
    }
    ObjectSpace.SetModified(View.CurrentObject);
}

 

 

 

To see the result, run the WinForms or ASP.NET application and do the following.

  1. Open a detail form for any object.
  2. Click the Clear Tasks button, which represents the Action you have implemented. A confirmation message will appear as shown in the image below.

 

要查看结果,请运行 WinForms 或ASP.NET应用程序,然后执行以下操作。

技术分享图片

Click Yes (in a WinForms application) or OK (in an ASP.NET application). All Tracked Tasks of the Contact will be emptied.

单击"是"(在 WinForms 应用程序中)或"确定"(在ASP.NET应用程序中)。联系人的所有跟踪任务都将清空。

技术分享图片

Note  注意

Although this topic explains how to create a controller using the Designer, a controller is a class that can also be written manually, as shown in the Customize the Application UI and Behavior topic of the Basic Tutorial (SimpleProjectManager Application).

尽管本主题说明如何使用 Designer 创建控制器,但控制器是一个也可以手动写入的类,如基本教程(简单项目经理应用程序)的"自定义应用程序 UI 和行为"主题所示。

 

­

If you need to place an action inside the Detail View, refer to the How to: Include an Action to a Detail View Layout topic.

如果需要在"详细信息视图"中放置操作,请参阅"如何:将操作包括在"详细信息视图布局"主题中。

 

You can view the code used in this lesson in the MySolution.Module | Controllers | ClearContactTasksController.cs (ClearContactTasksController.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
您可以在 MySolution.模块中查看本课中使用的代码。控制器 |ClearContactTasksController.cs(清除联系人任务控制器.vb)文件的主要演示安装与XAF。主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

.

原文:https://www.cnblogs.com/foreachlife/p/Add-a-Simple-Action.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!