学习008-01-03 Customize the Application UI and Behavior(自界说应用步伐UI和举动) [复制链接]
发表于 2026-4-24 09:00:10 | 显示全部楼层 |阅读模式
Customize the Application UI and Behavior(自界说应用步伐UI和举动)

In XAF, the data model defines the database structure and UI. Changes to your entity classes affect the UI. For example, if you add a new property to an entity class, a new editor appears in the corresponding List and Detail views.
在XAF中,数据模子界说了数据库布局和UI。对实体类的更改会影响UI。比方,如果向实体类添加新属性,则会在相应的List和Detail视图中表现新的编辑器。
You can use the auto-generated UI or customize it according to your business requirements and scenarios. This topic describes how to customize your application’s appearance and behavior.
您可以使用主动天生的UI或根据您的业务需求和场景对其举行自界说。本主题先容怎样自界说应用步伐的表面和举动。
Customize the Application UI Metadata(自界说应用步伐UI元数据)

Use Attributes in Code(在代码中使用属性)

You can use built-in attributes to edit the Application Model, create controls, and customize the application’s appearance and behavior. For example, you can validate field content, change field visibility, or format displayed data with one line of code.
您可以使用内置属性来编辑应用步伐模子、创建控件以及自界说应用步伐的表面和举动。比方,您可以使用一行代码验证字段内容、更改字段可见性或格式化表现的数据。
Follow the steps below to replace the Quote property’s single-line editor with a multi-line editor.
按照以下步调将Quote属性的单行编辑器更换为多行编辑器。
1.Apply the FieldSizeAttribute attribute to the Quote property in the Testimonial class and pass Unlimited as the attribute’s parameter.
将FieldSizeAtoral属性应用于Testimonial类中的Quote属性,并将Unlimited作为属性的参数转达。
C#
  1. // ...
  2. namespace SimpleProjectManager.Module.BusinessObjects {
  3.     // ...
  4.     public class Testimonial {
  5.         [FieldSize(FieldSizeAttribute.Unlimited)]
  6.         public virtual string Quote { get; set; }
  7.         // ...
  8.     }
  9. }
复制代码
2.Run the application and open the Testimonial Detail View. The Quote property editor now supports multi-line input:
运行应用步伐并打开Testimonial Detail View。Quote属性编辑器如今支持多行输入:
ASP.NET Core Blazor

Windows Forms

Use the Model Editor(使用模子编辑器)

XAF exports data model settings to the application’s metadata (Application Model). If you do not want to define the application’s UI structure and behavior in your data model code, edit the application metadata in the Model Editor. Each project stores metadata settings as XML markup in XAMFL files. These files form the Application Model’s layered structure.
XAF将数据模子设置导出到应用步伐的元数据(应用步伐模子)。如果不想在数据模子代码中界说应用步伐的UI布局和举动,请在模子编辑器中编辑应用步伐元数据。每个项目都将元数据设置存储为XAMFL文件中的XML标志。这些文件构成应用步伐模子的分层布局。
Follow the steps below to change the Customer object’s caption in the Model Editor:
按照以下步调在模子编辑器中更改客户对象的标题:
1.In the SimpleProjectManager.Module project, double-click the Model.DesignedDiffs.xafml file to open it in the Model Editor.
在SimpleProjectManager模块项目中,双击Model. DesignedDiffs.xafml文件以在模子编辑器中打开它。
2.In the Model Editor node tree, navigate to the BOModel | SimpleProjectManager.Module.BusinessObjects | Customer node and set the ObjectCaptionFormat property to {0:FullName}.
在模子编辑器节点树中,导航到BOModel | SimpleProjectManager.Module.BusinessObjects | Customer节点,并将ObjectCaptionFormat属性设置为{0:FullName}。

3.Run the application. The caption of the Customer Detail View now displays the FullName property value.
运行应用步伐。客户具体信息视图的标题如今表现FullName属性值。
ASP.NET Core Blazor

Windows Forms

Define Custom Logic and UI Elements(界说自界说逻辑和UI元素)

You can use the Model Editor and built-in attributes to change UI element and control options. Alternatively, you can create Controllers and Actions in code to replace the application’s default UI elements or implement custom business logic.
您可以使用模子编辑器和内置属性来更改UI元素和控件选项。大概,您可以在代码中创建控制器和操纵来更换应用步伐的默认UI元素或实现自界说业务逻辑。
A Controller is a component you use to change application flow, customize UI elements, and implement custom user interaction. Controllers can include Actions. XAF renders Actions in the UI as interactive elements, such as buttons or menu items.
Controller是用于更改应用步伐流程、自界说UI元素和实现自界说用户交互的组件。控制器可以包罗Actions。XAF将UI中的Actions出现为交互式元素,比方按钮或菜单项。
Follow the steps below to implement a SimpleAction that allows users to mark the selected task as completed and sets the EndDate property of the ProjectTask object to the current date and time:
按照以下步调实现SimpleAction,答应用户将选定的使命标志为已完成,并将ProjectTask对象的EndDate属性设置为当前日期和时间:
1.In the Solution Explorer, go to the MySolution.Module project, right-click the Controllers folder, and choose Add DevExpress Item | New Item… from the context menu to invoke the Template Gallery. Select the XAF Controllers | View Controller Visual Studio template, specify ProjectTaskController as the new item’s name, and click Add Item.
在办理方案资源管理器中,转到MySolutions. Module项目,右键单击控制器文件夹,然后从上下文菜单中选择Add DevExpress Item | New Item…以调用模板库。选择the XAF Controllers | View Controller Visual Studio template,将ProjectTaskController指定为新项目标名称,然后单击添加项目。
2.Visual Studio displays an autogenerated ProjectTaskController.cs file with a View Controller declaration. Add the following code to the controller constructor:
Visual Studio表现带有View Controller声明的主动天生的ProjectTaskController. cs文件。将以下代码添加到控制器构造函数:
C#
  1. using DevExpress.ExpressApp;
  2. using SimpleProjectManager.Module.BusinessObjects;
  3. namespace SimpleProjectManager.Module.Controllers {
  4.     public class ProjectTaskController : ViewController {
  5.         public ProjectTaskController() {
  6.             // Specify the type of objects that can use the Controller.
  7.             TargetObjectType = typeof(ProjectTask);
  8.             // Activate the Controller in any type of View.
  9.             TargetViewType = ViewType.Any;
  10.             SimpleAction markCompletedAction = new SimpleAction(this, "MarkCompleted",
  11.                 DevExpress.Persistent.Base.PredefinedCategory.RecordEdit) {
  12.                 TargetObjectsCriteria =
  13.                 (CriteriaOperator.FromLambda<ProjectTask>(t => t.Status != ProjectTaskStatus.Completed)).ToString(),
  14.                 ConfirmationMessage =
  15.                 "Are you sure you want to mark the selected task(s) as 'Completed'?",
  16.                 ImageName = "State_Task_Completed"
  17.             };
  18.             markCompletedAction.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
  19.             markCompletedAction.Execute += (s, e) => {
  20.                 foreach (ProjectTask task in e.SelectedObjects) {
  21.                     task.EndDate = DateTime.Now;
  22.                     task.Status = ProjectTaskStatus.Completed;
  23.                     View.ObjectSpace.SetModified(task);
  24.                 }
  25.                 View.ObjectSpace.CommitChanges();
  26.                 View.ObjectSpace.Refresh();
  27.             };
  28.         }
  29.     }
  30.     // ...
  31. }
复制代码
In the code above, the Object Space’s IObjectSpace.CommitChanges method commits changes to the database. An Object Space entity is an ORM-independent implementation of the Repository and Unit Of Work design patterns. Object Space allows you to query or modify data in the transaction. Refer to the following help topic for information on other Object Space methods: Create, Read, Update and Delete Data.
在上面的代码中,Object Space的IObjectSpace.CommitChanges方法向数据库提交更改。Object Space实体是Repository和Unit Of Work筹划模式的与ORM无关的实现。Object Space答应您查询或修改变乱中的数据。有关其他Object Space方法的信息,请参阅以下资助主题:创建、读取、更新和删除数据。
Run the application and mark the selected task as completed.
运行应用步伐并将选定的使命标志为已完成。
ASP.NET Core Blazor

Windows Forms

When you apply this action to multiple objects, it iterates through the selected objects, modifies their properties, commits changes to the database, and refreshes the screen.
当您将此操纵应用于多个对象时,它会遍历选定的对象、修改它们的属性、将更改提交到数据库并革新屏幕。
Next Lesson(下一课)

Reuse Implemented Functionality
重用实现的功能

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表