Add a Simple Action添加简单按钮
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 属性设置为"详细信息视图"。因此,控制器将仅在详细窗体中激活。

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>控制器,而不是视图控制器,并指定应为其激活此控制器的视图类型。
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.
- Open a detail form for any object.
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添加简单按钮的更多相关文章
- 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 ...
- Add a Parametrized Action 添加带参数的按钮
In this lesson, you will learn how to add a Parametrized Action. These types of Actions are slightly ...
- Specify Action Settings 指定按钮设置
In this lesson, you will learn how to modify Action properties. The ClearTasks Action will be used. ...
- 127使用 TableView 自带的单元格样式实现好友列表,另外在单元格中添加辅助按钮
类似的做法如之前这篇随笔:114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果) 相比之下:自定义 UITableViewCell 的内容灵活,可根据需求 ...
- ios在数字键盘左下角添加“完成”按钮的实现原理
本文转载至 http://www.itnose.net/detail/6145865.html 最近要在系统弹出的数字键盘上的左下角额外添加一个自定制的完成按钮,于是研究了一下系统自带键盘添加自定制按 ...
- iOS 为键盘添加隐藏按钮
// 为键盘添加隐藏按钮 UIToolbar * backView = [[UIToolbar alloc]initWithFrame:CGRectMake(, , , )]; [backView s ...
- C# mvc中为Controller或Action添加定制特性实现登录验证
在本文开始前,先简单讲两个知识点: 1.每个action执行前都会先执行OnActionExecuting方法: 2.FCL提供了多种方式来检测特性的存在,比如IsDefined.GetCustomA ...
- iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)
自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...
- cocos2dx游戏--欢欢英雄传说--添加攻击按钮
接下来添加攻击按钮用于执行攻击动作.同时修复了上一版移动时的bug.修复后的Player::walkTo()函数: void Player::walkTo(Vec2 dest) { if (_seq) ...
随机推荐
- js反爬学习(一)谷歌镜像
1. url:https://ac.scmor.com/ 2. target:如下链接 3. 过程分析: 3.1 打开chrome调试,进行元素分析.随便定位一个“现在访问” 3.2 链接不是直接挂在 ...
- Seafile对接Amazon S3存储后端
安装python第三方库boto easy_install boto 进入seafile配置文件.conf添加下面内容 [commit_object_backend] name = s3 bucket ...
- Mac VMware Fusion CentOS7配置静态IP
目录 安装CentOS7 配置静态IP 安装CentOS7 这里我们要安装CentOS7 64位,所以选择CentOS7 64位配置 我们点击存储后,vmware会自动帮我们创建一个虚拟机,但是我们还 ...
- antdesign的input增加自定义校验规则
rules: [ {required: true, message: '请输入姓名'}, {max: 16, message: '姓名过长'}, { validator: (rule, val, ca ...
- mysql存储4字节的表情包数据报异常_Emoji表情包_Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
本文章转载自:https://www.cnblogs.com/coprince/p/7485968.html 原文如下: 问题描述:从新浪微博抓取消息保存到MySQL数据中,对应数据库字段为varch ...
- SAP FI 问题汇总
记录工作中遇到的问题汇总 1.固定资产折旧码的设置 2.与资产有关的日期 3.如何添加固定资产分类
- 47.QT-QChart之曲线图,饼状图,条形图使用
1.使用准备 在pro中, 添加QT+= charts 然后在界面头文件中添加头文件并声明命名空间,添加: #include <QtCharts> QT_CHARTS_USE_NAMES ...
- 如何实现用户的历史记录功能(最多n条)
使用容量为n的队列存储历史记录 使用标准库collections中的deque,它是一个双端循环队列 from collections import deque q = deque([], 5) #参 ...
- Python内置装饰器@property
在<Python装饰器(Decorators )>一文中介绍了python装饰器的概念,日常写代码时有一个装饰器很常见,他就是内置的@property. 我们一步步的来接近这个概念. 一个 ...
- 教你如何在5分钟轻松部署squid正向代理
正向代理是一个位于客户端和原始服务器(origin server)之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返 ...