Access the Settings of a Property Editor in a Detail View(在详细信息视图中访问属性编辑器的设置)
This lesson explains how to access editors in a Detail View and change their settings.
本课介绍如何访问详细信息视图中的编辑器并更改其设置。
The instructions below show how to make the Birthday property editor display a scrollable date picker in its drop-down window.
下面的说明展示了如何使Birthday属性编辑器在其下拉窗口中显示可滚动的日期选择器。
Note
Before you proceed, take a moment to review the previous lessons:
在继续之前,请花点时间回顾一下之前的课程:
- Implement a Data Model: Basics
- Add a Simple Action
Step-by-Step Instructions(分步说明)
1.In the MySolution.Blazor.Server and MySolution.Win projects, add a View Controller to the Controllers folder. Name the new controller DateEditCalendarController. Specify the controller ancestor class ObjectViewController<ViewType, ObjectType>:
在MySolutions. Blazor.Server和MySolution.Win项目中,将View Controller添加到Controller文件夹。将新控制器命名为DateEditCalendarController。指定控制器祖先类ObjectViewController<ViewType,ObjectType>:
ASP.NET Core Blazor
C#
using DevExpress.ExpressApp;
using MySolution.Module.BusinessObjects;
// ...
namespace MySolution.Blazor.Server.Controllers {
public class DateEditCalendarController : ObjectViewController<DetailView, Employee> {
// ...
}
}
Windows Forms
C#
using MySolution.Module.BusinessObjects;
namespace MySolution.Win.Controllers {
public class DateEditCalendarController : ObjectViewController<DetailView, Employee> {
public DateEditCalendarController() {
//...
}
// ...
}
}
The DateEditCalendarController inherits from the ObjectViewController<ViewType, ObjectType> base class. The parameters of the base class enable the Controller only for Detail Views that display and edit Employee objects.
DateEditCalendarController继承自ObjectViewController<ViewType, ObjectType>基类。基类的参数仅为显示和编辑员工对象的详细信息视图启用控制器。
2.Override the OnActivated method. Use the DetailViewExtensions.CustomizeViewItemControl method to access the Birthday property editor settings:
覆盖OnActivated方法。使用DetailViewExtensions.CustomizeViewItemControl方法访问Birthday属性编辑器设置:
ASP.NET Core Blazor
C#
// ...
using DevExpress.ExpressApp.Blazor.Editors;
namespace MySolution.Blazor.Server.Controllers {
public partial class DateEditCalendarController : ObjectViewController<DetailView, Employee> {
protected override void OnActivated() {
base.OnActivated();
//Access the Birthday property editor settings
View.CustomizeViewItemControl<DateTimePropertyEditor>(this, SetCalendarView, nameof(Employee.Birthday));
}
private void SetCalendarView(DateTimePropertyEditor propertyEditor) {
//Set the date picker display mode to scroll picker
propertyEditor.ComponentModel.PickerDisplayMode = DevExpress.Blazor.DatePickerDisplayMode.ScrollPicker;
}
}
}
Windows Forms
C#
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.XtraEditors;
using MySolution.Module.BusinessObjects;
namespace MySolution.Win.Controllers {
//...
public class DateEditCalendarController : ObjectViewController<DetailView, Employee> {
public DateEditCalendarController() {
// ...
}
protected override void OnActivated() {
base.OnActivated();
//Access the Birthday property editor settings
View.CustomizeViewItemControl(this, SetCalendarView, nameof(Employee.Birthday));
}
private void SetCalendarView(ViewItem viewItem)
{
//Set the currently displayed View Item control to a drop-down calendar
DateEdit dateEdit = (DateEdit)viewItem.Control;
//Set the appearance of the calendar in the drop-down window
dateEdit.Properties.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.TouchUI;
}
//...
}
}
3.Run the application and open the Employee Detail View. The Birthday editor shows a scrollable date picker in its drop-down window:
运行应用程序并打开员工详细信息视图。生日编辑器在其下拉窗口中显示了一个可滚动的日期选择器:
ASP.NET Core Blazor
Windows Forms
Tip
For general information on Property Editor architecture and UI Controls used by XAF, review the following articles:
有关XAF使用的属性编辑器体系结构和UI控件的一般信息,请查看以下文章:
- Implement a Property Editor Based on a Custom Component (Blazor)(实现基于自定义组件(Blazor)的属性编辑器)
- Implement a Property Editor Based on a Custom Control (WinForms)(实现基于自定义控件(WinForms)的属性编辑器)
- Data Types Supported by built-in Editors(内置编辑器支持的数据类型)
Next Lesson(下一课)
Format a Property Value
格式化属性值