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) ...
随机推荐
- 设计模式之单例模式C#实现
前言 单例模式是老生常谈的一种设计模式,同时它是最简单也是最容易被忽视的一种设计模式. 下面是一些个人看法: (1) 单例类需要保证自己的唯一性,同时也需要避免被继承,即需要使用sealed修饰: ( ...
- MS14-068(CVE-2014-6324)域控提权利用及原理解析
漏洞利用 0x01 漏洞利用前提 1.域控没有打MS14-068的补丁(KB3011780) 2.拿下一台加入域的计算机 3.有这台域内计算机的域用户密码和Sid 0x02 工具下载 Ms14-068 ...
- docker快速部署本地项目到服务器(tomcat8+mysql8)
目标是:将本地运行的spring项目,部署到服务器上 为什么使用docker? 环境隔离 服务器上,各种环境交杂,使用docker,能清楚的把各个项目进行隔离,不单维护的人员方便,也会省去很多维护这些 ...
- 如何把Mybatis的Mapper.xml配置文件和dao接口放在同一个包下
有的时候我们在Maven项目中写关于Mybatis的项目时,会涉及到很多的实体类,也就会涉及到很多的dao接口,如果此时我们仍然把dao接口和xml写在同一个包下,会让项目接口变得很乱,杂七杂八的,所 ...
- 面试连环炮系列(五):你们的项目为什么要用RabbitMQ
你们的项目为什么要用RabbitMQ? 消息队列的作用是系统解耦.同步改异步.请求消峰,举个下订单的例子: 前端获取用户订单信息,请求后端的订单创建接口.这个接口并不直接请求订单服务,而是首先生成唯一 ...
- IT兄弟连 HTML5教程 CSS3属性特效 倒影
在Web制作中,有些时候需要实现一些倒影的效果.在传统网页中,我们只能使用photoshop事先将倒影设计好,然后导入到网页中,这样不但耗费资源,也阻碍了开发效率.而CSS新增了Reflections ...
- 如何Windows下配置Prometheus的监控数据文件为3天
如上图,prometheus的data文件夹时间久了会变得很大,听说是保留15天的数据.但是实际上,我只需要保留3天的数据就够了,之前试过用批处理文件清理,但是强行删除会导致peometheus崩溃, ...
- 一起学SpringMVC之文件上传
概述 在Web系统开发过程中,文件上传是普遍的功能,本文主要以一个简单的小例子,讲解SpringMVC中文件上传的使用方法,仅供学习分享使用,如有不足之处,还请指正. 文件上传依赖包 如下所示,文件上 ...
- MFC程序出现uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)解决办法
在同一个地方摔倒两次之后,决定记录下来这个东西. 问题 1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl opera ...
- Spring MVC 解决乱码
1. Spring 事务处理 Spring MVC乱码问题 三种处理数据库的方式 (1)jdbc(J2EE规范) (2)Spring JDBCTemplate( ...