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.

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

  • The XAF Controllers | View Controller Visual Studio template makes it easier to add a View Controller to your application. In the Solution Explorer, right-click the Controllers folder in the MySolution.Module project, and choose Add DevExpress Item | New Item... to invoke Template Gallery. Then select View Controller, specify ClearContactTasksController as the new item's name and click Add Item. As a result, you will get an automatically generated ClearContactTasksController.cs (ClearContactTasksController.vb) file with a single View Controller declaration.

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

  • The new Controller will be activated within any type of View by default. Because the task of this lesson is to clear Tracked Tasks in a Detail View, the default behavior should be changed. Right-click the MySolution.Module | Controllers | ClearContactTasksController.cs (ClearContactTasksController.vb) file, and choose View Designer to invoke the Designer.

  • 默认情况下,将在任何类型的视图中激活新控制器。由于本课的任务是清除详细信息视图中的"跟踪任务",因此应更改默认行为。右键单击"我的解决方案"模块 |控制器 |ClearContactTasksController.cs(清除联系人任务控制器.vb)文件,然后选择"视图设计器"以调用设计器。

  • In the Properties window for the controller, set the TargetViewType property to the DetailView. As a result, the controller will only be activated in detail forms.

  • 在控制器的"属性"窗口中,将 TargetViewType 属性设置为"详细信息视图"。因此,控制器将仅在详细窗体中激活。

  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 操作部分中,将"简单操作"拖动到设计器。

  • In the Properties window for SimpleAction, set the Name and ID properties to "ClearTasksAction", the Category property to "View", the ImageName property to "Action_Clear" and the Caption property to "Clear Tasks". Set the ConfirmationMessage property to "Are you sure you want to clear the Tasks list?".

  • 在"简单操作的属性"窗口中,将"名称"和"ID"属性设置为"清除任务操作",将"类别"属性设置为"查看",将 ImageName 属性设置为"Action_Clear",将"标题"属性设置为"清除任务"。将"确认消息"属性设置为"是否确实要清除任务列表"。"

    Note 注意

    The Category property specifies the Action group to which the current Action belongs. All Actions within one group are displayed sequentially in a UI.

    The ImageName property specifies the icon of the Action's button in the interface. You can use one of the standard images or import your own

    "类别"属性指定当前操作所属的操作组。一个组内的所有操作都按顺序显示在 UI 中。
    ImageName 属性指定界面中操作按钮的图标。您可以使用其中一个标准映像或导入您自己的

  • A SimpleAction is designed to execute specific code when an end-user clicks it. To clear the Tasks collection of the current Person and refresh the view, implement the action's Execute event handler. Switch to the Events view in the Properties window, double-click the Execute event and add the following code to the auto-generated event handler.

  • SimpleAction 旨在在最终用户单击特定代码时执行该代码。要清除当前人员的任务集合并刷新视图,请实现操作的 Execute 事件处理程序。切换到"属性"窗口中的事件视图,双击 Execute 事件并将以下代码添加到自动生成的事件处理程序。

  • Entity Framework

实体框架

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 > ) {
((Contact)View.CurrentObject).Tasks.Remove(((Contact)View.CurrentObject).Tasks[]);
}
ObjectSpace.SetModified(View.CurrentObject);
}
  • In ASP.NET Web applications, there are two modes for displaying Detail Views - View mode and Edit mode. The ClearTasks Action should only be available when a Detail View is displayed in Edit mode, so check to see if the edit mode for the current Detail View has changed. If it has changed to View mode, the Action should be disabled. To implement this, you should review the following concepts.

  • 在ASP.NET Web 应用程序中,有两种模式可用于显示详细视图 - 视图模式和编辑模式。仅当"详细信息视图"在"编辑"模式下显示时,"清除任务"操作才应可用,因此请检查当前"详细信息视图"的编辑模式是否已更改。如果它已更改为"查看"模式,则应禁用操作。为此,您应该查看以下概念。

    • The Detail View exposes the DetailView.ViewEditModeChanged event, which is fired when the edit mode is changed.
    • The Action exposes the ActionBase.Enabled property, which is not a simple Boolean property, but a key/value pair collection used to determine the Action's enabled state. This kind of collection is used because there can be many factors that influence the Action's state, and an XAF application should take them all into account.
    • "详细视图"公开"详细信息视图.ViewEditModeChanged"事件,该事件在更改编辑模式时触发。
    • 操作公开 ActionBase.Enabled 属性,该属性不是简单的布尔属性,而是用于确定操作的启用状态的键/值对集合。之所以使用此类集合,是因为影响 Action 状态的因素很多,XAF 应用程序应将所有因素都考虑在内。
  • Thus, handle the ViewEditModeChanged event and modify the Action's Enabled collection based on the current edit mode. To do this, return to the Controller's Designer and double-click the Activated event in the Events view of the Properties window. Replace the automatically generated event handler with the following code.

  • 因此,处理 ViewEditModeChanged 事件,并根据当前编辑模式修改操作的"已启用"集合。为此,返回到控制器的设计器,并双击"属性"窗口的"事件"视图中的"已激活"事件。将自动生成的事件处理程序替换为以下代码。

    private void ClearContactTasksController_Activated(object sender, EventArgs e) {
    // Enables the ClearTasks Action if the current Detail View's ViewEditMode property
    // is set to ViewEditMode.Edit.
    ClearTasksAction.Enabled.SetItemValue("EditMode",
    ((DetailView)View).ViewEditMode == ViewEditMode.Edit);
    ((DetailView)View).ViewEditModeChanged +=
    new EventHandler<EventArgs>(ClearContactTasksController_ViewEditModeChanged);
    }
    // Manages the ClearTasks Action enabled state.
    void ClearContactTasksController_ViewEditModeChanged(object sender, EventArgs e) {
    ClearTasksAction.Enabled.SetItemValue("EditMode",
    ((DetailView)View).ViewEditMode == ViewEditMode.Edit);
    }

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/

.

Add a Simple Action添加简单按钮的更多相关文章

  1. Add a Simple Action using an Attribute 使用特性添加简单按钮

    In the previous Add a Simple Action lesson, you learned how to add an Action by implementing the Vie ...

  2. Add a Parametrized Action 添加带参数的按钮

    In this lesson, you will learn how to add a Parametrized Action. These types of Actions are slightly ...

  3. Specify Action Settings 指定按钮设置

    In this lesson, you will learn how to modify Action properties. The ClearTasks Action will be used. ...

  4. 127使用 TableView 自带的单元格样式实现好友列表,另外在单元格中添加辅助按钮

    类似的做法如之前这篇随笔:114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果) 相比之下:自定义 UITableViewCell 的内容灵活,可根据需求 ...

  5. ios在数字键盘左下角添加“完成”按钮的实现原理

    本文转载至 http://www.itnose.net/detail/6145865.html 最近要在系统弹出的数字键盘上的左下角额外添加一个自定制的完成按钮,于是研究了一下系统自带键盘添加自定制按 ...

  6. iOS 为键盘添加隐藏按钮

    // 为键盘添加隐藏按钮 UIToolbar * backView = [[UIToolbar alloc]initWithFrame:CGRectMake(, , , )]; [backView s ...

  7. C# mvc中为Controller或Action添加定制特性实现登录验证

    在本文开始前,先简单讲两个知识点: 1.每个action执行前都会先执行OnActionExecuting方法: 2.FCL提供了多种方式来检测特性的存在,比如IsDefined.GetCustomA ...

  8. iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)

    自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...

  9. cocos2dx游戏--欢欢英雄传说--添加攻击按钮

    接下来添加攻击按钮用于执行攻击动作.同时修复了上一版移动时的bug.修复后的Player::walkTo()函数: void Player::walkTo(Vec2 dest) { if (_seq) ...

随机推荐

  1. linux中文件压缩介绍

    原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/1c62bb7f-f ...

  2. JS---DOM---事件冒泡和阻止事件冒泡,总结事件

    事件冒泡: 多个元素嵌套, 有层次关系 ,这些元素都注册了相同的事件, 如果里面的元素的事件触发了, 外面的元素的该事件自动的触发了     事件有三个阶段: 1.事件捕获阶段  :从外向内 2.事件 ...

  3. 面试连环炮系列(一):如何保证Redis高可用和高并发

    如何保证Redis高可用和高并发? Redis主从架构,一主多从,可以满足高可用和高并发.出现实例宕机自动进行主备切换,配置读写分离缓解Master读写压力. Redis高可用方案具体怎么实施? 使用 ...

  4. 浅析ketamahash和murmurhash

    说来赶巧,之前我有16个redis集群,然后我要将某个key根据路由规则存到16个集群中的某一个上面,正巧用到了这两种哈希算法,改造完毕上线后,整体带来的效果也十分理想. 说道ketamahash,它 ...

  5. C#开发微信小程序(二)

    导航:C#开发微信小程序系列 关于小程序项目结构,框架介绍,组件说明等,请查看微信小程序官方文档,关于以下贴出来的代码部分我只是截取了一些片段,方便说明问题,如果需要查看完整源代码,可以在我的项目库中 ...

  6. python通过http下载文件的方法

    1.通过requests.get方法 r = requests.get("http://200.20.3.20:8080/job/Compile/job/aaa/496/artifact/b ...

  7. JAVA集合框架(三)-Map

    前言 Map是java中用于存储键值对映射的接口.是解决编程问题最常用的数据结构之一.在工作中,有时候为实现一个功能可能写了好大一段代码,运行是ok了,但是就是不想回头再看,不敢相信自己写的这么烂.这 ...

  8. PLSQL设置查询快捷键

    Tools-->Preferences-->User Interface-->Editor-->AutoReplace 新建文本文件shortcut.txt(名称和路径可以自定 ...

  9. JavaWeb入门——在Windows环境下安装Tomcat服务器

    JavaWeb入门——在Windows环境下安装Tomcat服务器 摘要:本文主要学习如何在Windows环境中下载并安装Tomcat服务器. 下载 获取安装包 推荐去官网上下载Tomcat: htt ...

  10. 使用“npm init”初始化项目

    使用npm init初始化项目 为什么要使用npm init初始化项目 在node开发中使用npm init会生成一个pakeage.json文件,这个文件主要是用来记录这个项目的详细信息的,它会将我 ...