Add an Action that Displays a Pop-up Window 添加显示弹出窗口按钮
In this lesson, you will learn how to create an Action that shows a pop-up window. This type of Action is useful when you want a user to input several parameters in a pop-up dialog before an Action is executed.
在本课中,您将学习如何创建显示弹出窗口的操作。当您希望用户在执行操作之前在弹出对话框中输入多个参数时,这种类型的操作非常有用。
Note 注意
Before proceeding, take a moment to review the following lessons.
- Set a Many-to-Many Relationship (XPO/EF)
- Add a Simple Action
在继续之前,请花点时间复习以下课程。
- 设置多对多关系 (XPO/EF)
- 添加简单操作
Create a Controller and a PopupWindowShowAction
创建控制器和弹出窗口窗口显示操作
- Add a new View Controller to the MySolution.Module project, as described in the Add a Simple Action lesson. Name it PopupNotesController.
Right-click the MySolution.Module | Controllers | PopupNotesController.cs (PopupNotesController.vb) file, and choose View Designer to invoke the Designer.
向 MySolution.Module 项目添加新的视图控制器,如"添加简单操作"一课中所述。将其命名为"弹出笔记控制器"。
右键单击"我的解决方案"模块 |控制器 |PopupNotesController.cs (PopupNotesController.vb) 文件,然后选择"视图设计器"以调用设计器。

Drag the PopupWindowShowAction component from the DX.19.2: XAF Actions tab to the Designer. In the popupWindowShowAction1 "Properties" window, set the Name and Id properties to "ShowNotesAction", and set the Caption property to "Show Notes". Set the Category property to "Edit". This property specifies the Action group to which the current Action belongs. All Actions within a single group are displayed together sequentially in a UI.
将"弹出窗口显示操作"组件从 DX.19.2:XAF 操作选项卡拖动到设计器。在弹出窗口WindowShowAction1"属性"窗口中,将"名称"和"ID"属性设置为"显示笔记操作",并将标题属性设置为"显示注释"。将"类别"属性设置为"编辑"。此属性指定当前操作所属的操作组。单个组中的所有操作在 UI 中按顺序一起显示。

To activate the PopupNotesController for DemoTask Detail Views only, set the Controller's ViewController.TargetObjectType property to MySolution.Module.DemoTask, and set the ViewController.TargetViewType to DetailView.
要仅激活演示任务详细信息视图的 PopupNotes 控制器,请将控制器的视图控制器.TargetTotos 类型属性设置为 MySolution.module.demoTask,并将视图控制器.TargetViewType设置为详细信息视图。

Specify the Popup List View
指定弹出列表视图
Focus the ShowNotesAction component. In the Properties window, switch to the Events view. Double-click the CustomizePopupWindowParams event, add the "using" ("Imports" in VB) directive according to your ORM, and replace the auto-generated event handler code with the following code.
聚焦"显示笔记操作"组件。在"属性"窗口中,切换到"事件"视图。双击"自定义PopupWindowParams"事件,根据您的ORM在VB中添加"使用"("导入")指令,并将自动生成的事件处理程序代码替换为以下代码。
using DevExpress.Persistent.BaseImpl; //For XPO
using DevExpress.Persistent.BaseImpl.EF; //For EF
// ...
private void ShowNotesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs args) {
IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Note));
string noteListViewId = Application.FindLookupListViewId(typeof(Note));
CollectionSourceBase collectionSource = Application.CreateCollectionSource(objectSpace, typeof(Note), noteListViewId);
args.View = Application.CreateListView(noteListViewId, collectionSource, true);
//Optionally customize the window display settings.
//args.Size = new System.Drawing.Size(600, 400);
//args.Maximized = true;
//args.IsSizeable = false;
}
For details on this event, refer to the PopupWindowShowAction.CustomizePopupWindowParams topic. The code above will create the Notes List View when generating the pop-up window.
To create a List View, use the XafApplication object again (as you did in the previous lesson). In the code above, the XafApplication helps you find the ID of the required List View in the Application Model. Note that a collection source for the List View is created in a separate Object Space. To create the Object Space, use XafApplication again.
有关此事件的详细信息,请参阅弹出窗口窗口显示操作。生成弹出窗口时,上述代码将创建"备注列表视图"。
要创建列表视图,请再次使用 XafApplication 对象(如上一课所示)。在上面的代码中,Xaf 应用程序可帮助您在应用程序模型中找到所需列表视图的 ID。请注意,列表视图的集合源是在单独的对象空间中创建的。要创建对象空间,请再次使用 Xaf 应用程序。
Handle the Execute Event
处理执行事件
In the Controller's Designer, switch to the Events view in the Properties window with the Action's properties. Double-click the Execute event, add the "using" ("Imports" in VB) directive and replace the auto-generated event handler code with the following code.
在控制器的设计器中,切换到"属性"窗口中的"事件"视图,该视图具有操作的属性。双击 Execute 事件,在 VB 中添加"使用"("导入")指令,并将自动生成的事件处理程序代码替换为以下代码。
using MySolution.Module.BusinessObjects;
// ...
private void ShowNotesAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs args) {
DemoTask task = (DemoTask)View.CurrentObject;
foreach(Note note in args.PopupWindowViewSelectedObjects) {
if(!string.IsNullOrEmpty(task.Description)) {
task.Description += Environment.NewLine;
}
task.Description += note.Text;
}
if(((DetailView)View).ViewEditMode == ViewEditMode.View) {
View.ObjectSpace.CommitChanges();
}
}
- The Execute event is raised when clicking the OK button in the pop-up window. When the handler above is executed, the Text property value of the selected Note object will be appended to the Task.Description property value.
- In this code, access the object selected in the pop-up window by using the event handler's PopupWindowShowActionExecuteEventArgs.PopupWindowViewSelectedObjects parameter.
- To refresh the editor representing the modified Description property, first find its PropertyEditor in the current View's CompositeView.Items collection using the CompositeView.FindItem method. To update the value displayed by the Property Editor's editor, call the PropertyEditor.ReadValue method.
- In ASP.NET Web applications, Detail Views are displayed in View and Edit modes. When the ShowNotes Action is activated for a DemoTask Detail View that is in View mode, the changes made to the DemoTask.Description property should be saved to the database. For this purpose, the CommitChanges method of the current View's ObjectSpace is called. When you use the ShowNotes Action in a DemoTask Detail View that is in Edit mode, the changes can be saved or rolled back via the corresponding built-in Actions.
- 单击弹出窗口中的"确定"按钮时引发"执行"事件。执行上述处理程序时,所选 Note 对象的 Text 属性值将追加到 Task.描述属性值。
- 在此代码中,使用事件处理程序的"弹出窗口显示操作执行事件"参数访问弹出窗口中选定的对象。
- 要刷新表示已修改的"描述"属性的编辑器,请首先在当前视图的"复合视图.项"集合中使用"复合视图.FindItem"方法查找其属性编辑器。要更新属性编辑器的编辑器显示的值,请调用属性编辑器.ReadValue 方法。
- 在ASP.NET Web 应用程序中,详细信息视图显示在"查看"和"编辑"模式下。当为处于"视图"模式的演示任务详细信息视图激活 ShowNotes 操作时,对 DemoTask.描述属性所做的更改应保存到数据库中。为此,将调用当前视图的对象空间的提交更改方法。在处于编辑模式的演示任务详细信息视图中使用 ShowNotes 操作时,可以通过相应的内置操作保存或回滚更改。
Add Notes to the UI
向 UI 添加注释
- To add the Note business class to the UI construction process, add it to the Application Model.
If your ORM is Entity Framework, you should register the Note type in DbContext before proceeding to the next step. Edit the BusinessObjects\MySolutionDbContext.cs file as shown below.
要将 Note 业务类添加到 UI 构造过程,请将其添加到应用程序模型中。
如果您的 ORM 是实体框架,则应在 DbContext 中注册 Note 类型,然后再继续执行下一步。编辑业务对象_MySolutionDbContext.cs 文件,如下所示。
public class MySolutionDbContext : DbContext {
//...
public DbSet<Note> Notes { get; set; }
}To add the Note business class from the Business Class Library use the Module Designer. Double-click the Module.cs (Module.vb) file within the MySolution.Module project. The Exported Types section of the designer lists the business classes that can be added.
要从商务舱库中添加 Note 业务类,请使用模块设计器。双击 MySolution.模块项目中的Module.cs(模块.vb)文件。设计器的"导出类型"部分列出了可添加的业务类。
If you are using XPO:
Locate the Referenced Assemblies | DevExpress.Persistent.BaseImpl.v19.2 | Note node.
- 如果您使用的是 XPO:
找到引用的程序集 |开发快车.持久.BaseImpl.v19.2 |注释节点。
If you are using Entity Framework:
Locate the Referenced Assemblies | DevExpress.Persistent.BaseImpl.EF.v19.2 | Note node.
- 如果您使用的是实体框架:
找到引用的程序集 |开发快车.持久.BaseImpl.EF.v19.2 |注释节点。
Select this node and press the SPACEBAR, or right-click it and choose Use Type in Application in the invoked context menu.
选择此节点并按空格键,或右键单击它,并在调用的上下文菜单中选择"在应用程序中使用类型"。

Build the project.
生成项目。

Note 注意
To create Note objects, you should add the Note item to the New Action's items. To do this, perform the steps demonstrated in the Add an Item to the New Action lesson.
To access the existing Note objects, add the Note item to the ShowNavigationItem Action's items (displayed by the navigation control). To do this, perform the steps demonstrated in the Add an Item to the Navigation Control lesson.
要创建 Note 对象,应将"注释"项添加到"新建操作"项中。为此,执行"将项目添加到新操作"一课中演示的步骤。
要访问现有的 Note 对象,将"注释"项添加到"显示导航项"操作的项目(由导航控件显示)。为此,执行"将项目添加到导航控制"一课中演示的步骤。
Result 结果
Run the WinForms or ASP.NET application. Create several Note objects via the New Action. Select the Task item in the navigation control. Double-click one of the listed Task objects. In the invoked detail form, find the Show Notes toolbar button that represents the implemented Action. Click this button, which will invoke a pop-up window. Select a Note object in the list and click OK. Check to see that the Task.Description property value has been changed.
运行 WinForms 或ASP.NET应用程序。通过"新建"操作创建多个 Note 对象。在导航控件中选择"任务"项。双击列出的任务对象之一。在调用的详细信息窗体中,查找表示已实现操作的"显示注释"工具栏按钮。单击此按钮,这将调用弹出窗口。在列表中选择"注意"对象,然后单击"确定"。检查任务描述属性值已更改。

Tip 提示
For an example of how to create and show a Detail View, refer to the How to: Create and Show a Detail View of the Selected Object in a Popup Window topic.
有关如何创建和显示详细信息视图的示例,请参阅"如何:在弹出窗口"主题中创建和显示选定对象的详细信息视图。
You can view the code demonstrated in this tutorial in the MySolution.Module | Controllers | PopupNotesController.cs (PopupNotesController.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.模块中演示的代码。控制器 |PopupNotesController.cs (PopupNotes控制器.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 an Action that Displays a Pop-up Window 添加显示弹出窗口按钮的更多相关文章
- Flex弹出窗口请求Action函数
Flex弹出窗口请求Action函数 private function askQuestion(event:MouseEvent):void { var askQuestions:AskWindow ...
- iOS开发技巧 - 使用Alerts和Action Sheets显示弹出框
解决方案: (Swift) 使用UIAlertController类 (Objective-C) 使用UIAlertView类 代码: (Swift) import UIKit class ViewC ...
- Add an Action with Option Selection 添加具有选项选择的按钮
In this lesson, you will learn how to create an Action with support for option selection. A new View ...
- 3D Touch开发全面教程之Peek and Pop - 预览和弹出
## 3D Touch开发全面教程之Peek and Pop - 预览和弹出 --- ### 了解3D Touch 在iPhone 6s和iPhone 6s Plus中Apple引入了3D Touch ...
- Android 使用弹出对话框,报Unable to add window错误
今天在使用Android弹出对话框的时候,报了一个unable to add window错误,我的代码如下 new AlertDialog.Builder(getApplicationContext ...
- 达到J2EE在后台action控制接待javascript弹出的对话框
1.后台Action于: request.setAttribute("message", "这项username要么password错误,请重新输入!"); 2 ...
- ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前
原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...
- 网页上弹出pop窗口实例,(document).height()与$(window).height()的区别
#dvbg{background-color:#666666; position:absolute; z-index:99; left:0; top:0; display:none; width:10 ...
- Python3基础 dict pop 弹出指定键的项
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
随机推荐
- Wiki语法大全
原文链接:wiki语法大全 编辑一个维客页面十分容易.只要点击页面上方的“编辑本页”或右侧的[编辑]链接即可修改该页,或点击“讨论本页”然后再点击“编辑页面”来讨论该页面.点击后您就会看到一个包含那 ...
- ObjectPool 对象池设计模式
Micosoft.Extension.ObjectPool 源码架构.模式分析: 三大基本对象: ObjectPool抽象类 ObjectPoolProvider抽象类 IPooledObjectPo ...
- 3.Redux学习3----redux-saga
redux-saga和redux-thunk功能差不多,都是为了避免直接在组件生命周期函数中做异步操作,便于自动化测试,便于拆分管理. 首先要下包 npm i redux-saga 第零步:在acti ...
- ES6 学习之 let
关于闭包: <html> <body> <div> <div> <button >aaa</button> <button ...
- Python 学习笔记(基础篇)
背景:今年开始搞 Data science ,学了 python 小半年,但一直没时间整理整理.这篇文章很基础,就是根据廖雪峰的 python 教程 整理了一下基础知识,再加上自己的一些拓展,方便自己 ...
- variable '' of type '' referenced from scope '', but it is not defined 异常解决方法
最近在做一个功能,通过拼接lamdba表达试来实现的功能,但测试时总是出现一个错误,如下图所示,网上也找不到答案,差点都放弃了.. 如上图图所示,我是想通过一个lamdba表达式(上图的IdField ...
- Centos7通过yum跟源码编译安装Nginx
源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.g ...
- LinkedHashMap源码学习
描述 可以按照添加元素的顺序对元素进行迭代的HashMap的子类. 注意,上面说的是加元素的顺序.也就是说,更新元素时,是不会影响遍历结构的的.除非设置参数accessOrder为true,将更新元素 ...
- golang 安装脚本
#!/bin/bash env sudo yum -y install wget curl echo "download golang ..." # 获取最新的golangurl ...
- 为什么 netstat 对某些服务只显示了 tcp6 监听端口
最近偶尔发现一个比较奇怪的现象,netstat 查看监听的服务端口时,却只显示了 tcp6 的监控, 但是服务明明是可以通过 tcp4 的 ipv4 地址访问的,那为什么没有显示 tcp4 的监听呢? ...