学习008-02-02-03 Add an Action that Displays a Pop-Up Window(添加显示弹出窗口的操作)

Add an Action that Displays a Pop-Up Window(添加显示弹出窗口的操作)

This lesson explains how to create an Action that shows a pop-up window. This type of Action is useful when users want to input multiple parameters in a pop-up dialog before they execute an Action.
本课介绍如何创建显示弹出窗口的Action。当用户想要在执行Action之前在弹出对话框中输入多个参数时,这种类型的Action很有用。

Note
Before you proceed, take a moment to review the previous lessons: 在继续之前,请花点时间回顾一下之前的课程:

  • Configure a Many-to-Many Relationship
  • Add a Simple Action

In this tutorial, you will implement the ability to add notes from a predefined list to task descriptions.
在本教程中,您将实现将预定义列表中的注释添加到任务描述中的功能。

Implement a New Entity(实现新实体)

1.Expand the MySolution.Module project and right-click the Business Objects folder. Choose Add | Class…. Specify Note.cs as the new class name and click Add.
展开MySolutions. Module项目并右键单击Business Objects文件夹。选择添加|类……将Note.cs指定为新类名,然后单击添加。

2.Replace the generated class declaration with the code sample below:
将生成的类声明替换为下面的代码示例:

C#

using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MySolution.Module.BusinessObjects;

[DefaultProperty(nameof(Text))]
[ImageName("BO_Note")]
public class Note {

    [Key, Browsable(false)]
    [DevExpress.ExpressApp.Data.Key]
    [VisibleInDetailView(false), VisibleInListView(false), VisibleInLookupListView(false)]
    public virtual Guid ID { get; set; }
    public virtual String Author { get; set; }
    public virtual DateTime? DateTime { get; set; }

    [FieldSize(FieldSizeAttribute.Unlimited)]
    public virtual String Text { get; set; }
}

3.Register the Note type in DbContext. Edit the BusinessObjects\MySolutionDbContext.cs file as shown below:
在DbContext中注册Note类型。编辑BusinessObjects\MySolutionDbContext. cs文件,如下所示:

C#

public class MySolutionEFCoreDbContext : DbContext {
    // ...
    public DbSet<Note> Notes { get; set; }
}

4.Add a migration and update the database. See the following section for details: Use a DBMS: Setup Migrations.
添加迁移并更新数据库。有关详细信息,请参阅以下部分:使用DBMS:设置迁移。

Create a View Controller(创建视图控制器)

1.Add a new View Controller to the MySolution.Module project. Name it PopupNotesController.
向MySolutions. Module项目添加一个新的视图控制器。将其命名为PopupNotesController。

2.In the PopupNotesController.cs file, specify the controller properties:
在PopupNotesController. cs文件中,指定控制器属性:

C#

using DevExpress.ExpressApp;
using MySolution.Module.BusinessObjects;
// ...
public partial class PopupNotesController : ViewController {
    // ...
    public PopupNotesController() {
        InitializeComponent();
        //Target the required Views and create their Actions
        TargetObjectType = typeof(DemoTask);
        TargetViewType = ViewType.DetailView;
    }
    // ...
}

3.Add the ShowNotesAction action and handle its CustomizePopupWindowParams event:
添加ShowNotesAction操作并处理其CustomizePopupWindowParams事件:

C#

public partial class PopupNotesController : ViewController {
    public PopupNotesController() {
        InitializeComponent();
        TargetObjectType = typeof(DemoTask);
        TargetViewType = ViewType.DetailView;
        /*Invoke a pop-up window with a specified View and execute custom code
          when a user clicks the OK or Cancel button.*/
        PopupWindowShowAction showNotesAction = new PopupWindowShowAction(this, "ShowNotesAction", PredefinedCategory.Edit) {
            Caption = "Show Notes"
        };


        showNotesAction.CustomizePopupWindowParams += ShowNotesAction_CustomizePopupWindowParams;
    }


    private void ShowNotesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
        //Create a List View for Note objects in the pop-up window.
        e.View = Application.CreateListView(typeof(Note), true);
    }
    // ...
}

4.Add and handle the ShowNotesAction’s Execute event. It occurs when a user clicks OK in the pop-up window. The event handler code appends the Note.Text property value to the Task.Description property value.
添加并处理ShowNotesAction的执行事件。当用户在弹出窗口中单击确定时发生。事件处理程序代码将Note. Text属性值附加到Task.Description属性值。

C#

// ...
public PopupNotesController() {
    // ...
    showNotesAction.Execute += ShowNotesAction_Execute;
}


private void ShowNotesAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
    DemoTask task = (DemoTask)View.CurrentObject;
    foreach(Note note in e.PopupWindowViewSelectedObjects) {
        if(!string.IsNullOrEmpty(task.Description)) {
            task.Description += Environment.NewLine;
        }
        // Add selected note texts to a Task's description
        task.Description += note.Text;
    }
    View.ObjectSpace.CommitChanges();
}

The event handler’s e.PopupWindowViewSelectedObjects parameter provides an object that a user selects in the pop-up window.
事件处理程序的e.PopupWindowViewSelectedObjects参数提供用户在弹出窗口中选择的对象。

5.Run the application.(运行应用程序。)

Open a Task item’s Detail View. The Detail View toolbar displays the Show Notes button. This is the action implemented in this lesson.
打开任务项的详细信息视图。详细信息视图工具栏显示显示注释按钮。这是本课中实现的操作。

Click the button to open the pop-up window. The pop-up window displays a list view for the Note objects. Create a Note object.
单击按钮打开弹出窗口。弹出窗口显示Note对象的列表视图。创建一个Note对象。

Click this Note object in the list. After that, the Task.Description property value changes.
单击列表中的此Note对象。之后,Task. Description属性值更改。

ASP.NET Core Blazor
在这里插入图片描述

Windows Forms
在这里插入图片描述

For an example of how to create and show a Detail View, refer to the following topic: How to: Create and Show a Detail View of the Selected Object in a Popup Window.
CodeRush允许您通过几次击键添加操作和控制器。要了解XAF的代码模板,请参阅以下帮助主题:XAF模板。

Note
CodeRush allows you to add Actions and Controllers with a few keystrokes. To learn about the Code Templates for XAF, refer to the following help topic: XAF Templates.
CodeRush允许您通过几次击键添加操作和控制器。要了解XAF的代码模板,请参阅以下帮助主题:XAF模板。

Next Lesson(下一课)

Add an Action with Option Selection
使用选项选择添加操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值