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 添加显示弹出窗口按钮的更多相关文章

  1. Flex弹出窗口请求Action函数

    Flex弹出窗口请求Action函数 private function askQuestion(event:MouseEvent):void { var askQuestions:AskWindow ...

  2. iOS开发技巧 - 使用Alerts和Action Sheets显示弹出框

    解决方案: (Swift) 使用UIAlertController类 (Objective-C) 使用UIAlertView类 代码: (Swift) import UIKit class ViewC ...

  3. 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 ...

  4. 3D Touch开发全面教程之Peek and Pop - 预览和弹出

    ## 3D Touch开发全面教程之Peek and Pop - 预览和弹出 --- ### 了解3D Touch 在iPhone 6s和iPhone 6s Plus中Apple引入了3D Touch ...

  5. Android 使用弹出对话框,报Unable to add window错误

    今天在使用Android弹出对话框的时候,报了一个unable to add window错误,我的代码如下 new AlertDialog.Builder(getApplicationContext ...

  6. 达到J2EE在后台action控制接待javascript弹出的对话框

    1.后台Action于: request.setAttribute("message", "这项username要么password错误,请重新输入!"); 2 ...

  7. ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前

    原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...

  8. 网页上弹出pop窗口实例,(document).height()与$(window).height()的区别

    #dvbg{background-color:#666666; position:absolute; z-index:99; left:0; top:0; display:none; width:10 ...

  9. Python3基础 dict pop 弹出指定键的项

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. 一个小工具帮你搞定实时监控Nginx服务器

    Linux运维工程师的首要职责就是保证业务7 x 24小时稳定的运行,监控Web服务器对于查看网站上发生的情况至关重要.关注最多的便是日志变动,查看实时日志文件变动大家第一反应应该是'tail -f ...

  2. python同步IO编程——StringIO、BytesIO和stream position

    主要介绍python两个内存读写IO:StringIO和BytesIO,使得读写文件具有一致的接口 StringIO 内存中读写str.需要导入StringIO >>> from i ...

  3. HTML连载57-相对定位和绝对定位

    一.定位流 1.分类 (1)相对定位: (2)绝对定位 (3)固定定位 (4)静态定位 2.什么相对定位 相对定位就是相对于自己以前在标准流中的位置来移动. 例子: <style> div ...

  4. Geoserver设置style

    1 背景 我们在ArcMap中可以直接通过symbol功能对图层进行定制化配图.但是,如果我们将配好图的shp图层在GeoServer中发布时,会发现图层样式完全丢失了.其实原因很简单,用ArcMap ...

  5. Android设置EditText不可编辑

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/224 禁用EditText 这个其实很简单,最简单的一种方 ...

  6. Scrum Meeting - 第六周【Alpha阶段】

    每日任务内容: 本次会议为第六次Scrum Meeting会议 本次会议项目经理召开时间为20:00,在北区男生宿舍楼召开,召开时长约15分钟,探讨了本周选课网站编写的后续工作. 小组成员 本周任务 ...

  7. delete和Vue.$delete删除数组的区别

    delete delete只是被删除的元素变成了 empty/undefined ,其他的元素的键值对应关系还是不变. Vue.$delete 直接删除了数组中元素,数组的键值对应关系发生相应变化 例 ...

  8. 微信小程序之启动页的重要性

    启动页在APP中是个很常见的需求,为什么对于小程序来说也非常重要呢?首先我描述一下我在开发过程中遇到的一些问题以及解决的步骤,到最后为什么要加启动页,看完你就明白了. 小程序的首页需要展示用户关注的小 ...

  9. ZKWeb网页框架3.0正式发布

    3.0 更新的内容有 更新 .NET 框架 替换项目模版的 netcoreapp2.2 到 netcoreapp3.0 目前支持的 .NET 框架有: net461, netcoreapp2.0, n ...

  10. .NET Core 3.0正式版发布

    是的,.NET Core 3.0正式版发布了,令人兴奋. WPF 其实,.NET Core 2.1开始已经是个很完善的版本,3.0又带来了什么呢?我站在我的使用角度来看,最最令人振奋的就是:能用WPF ...