zoukankan      html  css  js  c++  java
  • Access Editor Settings 访问编辑器设置

    This topic demonstrates how to access editors in a Detail View using a View Controller. This Controller searches the Contact Detail View for an Anniversary Property Editor that binds data to a control, and specifies that the control displays "N/A" when the Anniversary property value is not set. The "N/A" text is shown when the Detail View is in the Edit Mode (DetailView.ViewEditMode).

    本主题演示如何使用视图控制器访问详细信息视图中的编辑器。此控制器搜索联系人详细信息视图以寻找将数据绑定到控件的周年属性编辑器,并指定控件在未设置周年属性值时显示"N/A"。当详细视图处于编辑模式(详细信息视图.ViewEdit 模式)时,将显示"N/A"文本。

    Note 注意

    We recommend reviewing the following topics before proceeding:

    我们建议在继续之前查看以下主题:

    • Inherit from the Business Class Library Class (XPO/EF)
    • Add a Simple Action
    • 从商务舱库类 (XPO/EF) 继承
    • 添加简单操作

     

    To see the example discussed in this topic, access the MainDemo.Module.Win | Controllers or MainDemo.Module.Web | Controllers folder and open the WinNullTextEditorController.cs (WinNullTextEditorController.vb) or WebNullTextEditorController.cs (WebNullTextEditorController.vb) file. The MainDemo application is installed in %PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkMainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

    .要查看本主题中讨论的示例,请访问 MainDemo.module.Win |控制器或主模块.Web |控制器文件夹并打开WinNullTextEditorController.cs(WinNullText编辑器控制器.vb)或WebNullTextEditorController.cs(WebNullText编辑器控制器.vb)文件。主演示应用程序安装在%PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkMainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

    Access Editor Settings in a WinForms Application

    访问 WinForms 应用程序中的编辑器设置

    • Add a View Controller called "WinNullTextEditorController" to the MySolution.Module.Win project as described in the Add a Simple Action lesson (steps 1-3). Make sure you set the TargetViewType property to DetailView (step 3).

    • Override the OnActivated method. Use the CompositeView.FindItem method to get the Anniversary Property Editor from the current View's CompositeView.Items list which contains Property Editors and View Items.

    • In the OnActivated method, subscribe to the CompositeView.ItemsChanged event. Then, the Controller processes the Anniversary View Item that a user added at runtime. Otherwise, the Controller works only with the item included in the Detail View at design time.
    • Use the ViewItem.Control property to access the Anniversary Property Editor's control. Cast the control to the appropriate type to use its properties or subscribe to its events. See Data Types Supported by built-in Editors to determine the valid control type for a Property Editor. In the example below, the ViewItem.Control value is cast to the BaseEdit type.
    • Subscribe to the ViewItem.ControlCreated event and place your customization code in its handler to prohibit the control customization until the control is created.
    • 将名为"WinNullText编辑器控制器"的视图控制器添加到 MySolution.module.win 项目,如添加简单操作课(步骤 1-3)中所述。请确保将"目标视图"属性设置为"详细信息视图"(步骤 3)。
    • 覆盖 On 已激活的方法。使用"复合视图.FindItem"方法从当前视图的"复合视图"中获取周年属性编辑器。项目列表包含属性编辑器和视图项。
    • 在 On 已激活方法中,订阅复合视图.Items 更改事件。然后,控制器处理用户在运行时添加的周年视图项目。否则,控制器仅在设计时使用"详细信息视图"中包含的项目。
    • 使用 ViewItem.Control 属性访问周年属性编辑器的控件。将控件强制转换为适当的类型以使用其属性或订阅其事件。请参阅内置编辑器支持的数据类型,以确定属性编辑器的有效控件类型。在下面的示例中,ViewItem.Control 值将转换为 BaseEdit 类型。
    • 订阅 ViewItem.Control 创建事件,并将自定义代码放在其处理程序中,以禁止控件自定义,直到创建控件。

    The following code demonstrates the WinNullTextEditorController:

    以下代码演示了 WinNullText 编辑器控制器:

    using DevExpress.XtraEditors;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.Utils;
    // ...
    public partial class WinNullTextEditorController : ViewController {
        public WinNullTextEditorController() {
            InitializeComponent();
            RegisterActions(components);
        }
        private void InitNullText(PropertyEditor propertyEditor) {
            ((BaseEdit)propertyEditor.Control).Properties.NullText = CaptionHelper.NullValueText;
        }
        private void WinNullTextEditorController_ItemsChanged(Object sender, ViewItemsChangedEventArgs e) {
            if(e.ChangedType == ViewItemsChangedType.Added && e.Item.Id == "Anniversary") {
                TryInitializeAnniversaryItem();
            }
        }
        private void propertyEditor_ControlCreated(Object sender, EventArgs e) {
            InitNullText((PropertyEditor)sender);
        }
        protected override void OnActivated() {
            base.OnActivated();
            ((CompositeView)View).ItemsChanged += WinNullTextEditorController_ItemsChanged;
            TryInitializeAnniversaryItem();
        }
        protected override void OnDeactivated() {
            base.OnDeactivated();
            ((CompositeView)View).ItemsChanged -= WinNullTextEditorController_ItemsChanged;
        }
        public void TryInitializeAnniversaryItem() {
            PropertyEditor propertyEditor = ((DetailView)View).FindItem("Anniversary") as PropertyEditor;
            if(propertyEditor != null) {
                if(propertyEditor.Control != null) {
                    InitNullText(propertyEditor);
                }
                else {
                    propertyEditor.ControlCreated += new EventHandler<EventArgs>(propertyEditor_ControlCreated);
                }
            }
        }
    }

    Note that the WinNullTextEditorController uses the CaptionHelper.NullValueText property to get a localized "N/A" text.

    Run the WinForms application and open the Contact Detail View. The Anniversary editor shows the "N/A" text if the editor's value is unspecified.

    请注意,WinNullText编辑器控制器使用标题帮助器.NullValueText属性获取本地化的"不适用"文本。
    运行 WinForms 应用程序并打开"联系人详细信息"视图。如果未指定编辑器的值,则周年编辑器将显示"不适用"文本。

    Tutorial_EF_Lesson8_1

    Tip 提示

    This approach is not applicable to List View's in-place editors. To customize these editors, do one of the following:

    • Use a custom property editor as shown in the How to: Customize a Built-in Property Editor (WinForms) topic.
    • Access the List Editor control's events and properties as described in the Access Grid Control Properties article.

    此方法不适用于列表视图的就地编辑器。要自定义这些编辑器,请执行以下操作之一:

    • 使用自定义属性编辑器,如"如何:自定义内置属性编辑器 (WinForms)"主题中所示。
    • 访问列表编辑器控件的事件和属性,如访问网格控制属性一文中所述。

     

    Access Editor Settings in an ASP.NET Application

    访问ASP.NET应用程序中的编辑器设置

    • Add a View Controller called "WebNullTextEditorController" to the MySolution.Module.Web project as described in the Add a Simple Action topic (steps 1-3).
    • Override the OnActivated method. Use the CompositeView.FindItem method to get the Anniversary Property Editor from the current View's CompositeView.Items list. It contains Property Editors and View Items.
    • Use the WebPropertyEditor.Editor property to access the Anniversary Property Editor's control. Cast the control to the appropriate type to use its properties or subscribe to its events. See Data Types Supported by built-in Editors to determine the valid control type for a Property Editor. In the example below, the ViewItem.Control value is cast to the ASPxDateEdit type.
    • Subscribe to the ViewItem.ControlCreated event to ensure that the control was created before you customize it.
    • 将名为"WebNullText编辑器控制器"的视图控制器添加到 MySolution.module.Web 项目中,如"添加简单操作"主题(步骤 1-3)中所述。
    • 覆盖 On 已激活的方法。使用"复合视图.FindItem"方法从当前视图的"复合视图.项目"列表中获取周年属性编辑器。它包含属性编辑器和视图项。
    • 使用 WebPropertyEditor.Editor 属性访问周年属性编辑器的控件。将控件强制转换为适当的类型以使用其属性或订阅其事件。请参阅内置编辑器支持的数据类型,以确定属性编辑器的有效控件类型。在下面的示例中,ViewItem.Control 值强制转换为 ASPxDateEdit 类型。
    • 订阅 ViewItem.Control 创建事件,以确保在自定义控件之前已创建该控件。

    The following code demonstrates the WebNullTextEditorController:

    以下代码演示了 WebNullText编辑器控制器:

    using DevExpress.Web;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Web.Editors;
    using DevExpress.ExpressApp.Utils;
    using DevExpress.ExpressApp.Editors;
    // ...
    public partial class WebNullTextEditorController : ViewController {
        public WebNullTextEditorController() {
            InitializeComponent();
            RegisterActions(components);
        }
        private void InitNullText(WebPropertyEditor propertyEditor) {
            if(propertyEditor.ViewEditMode == DevExpress.ExpressApp.Editors.ViewEditMode.Edit) {
                ((ASPxDateEdit)propertyEditor.Editor).NullText = CaptionHelper.NullValueText;
            }
        }
        private void propertyEditor_ControlCreated(object sender, EventArgs e) {
            InitNullText((WebPropertyEditor)sender);
        }
        protected override void OnActivated() {
            base.OnActivated();
            WebPropertyEditor propertyEditor = ((DetailView)View).FindItem("Anniversary") as WebPropertyEditor;
            if(propertyEditor != null) {
                if(propertyEditor.Control != null) {
                    InitNullText(propertyEditor);
                }
                else {
                    propertyEditor.ControlCreated += new EventHandler<EventArgs>(propertyEditor_ControlCreated);
                }
            }
        }
        protected override void OnDeactivated() {
            base.OnDeactivated();
            ViewItem propertyEditor = ((DetailView)View).FindItem("Anniversary");
            if(propertyEditor != null) {
                propertyEditor.ControlCreated -= new EventHandler<EventArgs>(propertyEditor_ControlCreated);
            }
        }
    }

    Note that the WebNullTextEditorController uses the CaptionHelper.NullValueText property to get a localized "N/A" text.

    Run the ASP.NET application and open the Contact Detail View. The Anniversary editor shows the "N/A" text if the editor's value is unspecified.

    请注意,WebNullText编辑器控制器使用标题帮助器.NullValueText属性获取本地化的"不适用"文本。

    运行ASP.NET应用程序并打开"联系人详细信息"视图。如果未指定编辑器的值,则周年编辑器将显示"不适用"文本。

    Tutorial_EF_Lesson8_3

    Tip 提示

    This approach does not affect List View's in-place editors. To customize these editors as well, use the solution described in the How to: Customize a Built-in Property Editor (ASP.NET) topic. Alternatively, access the required in-place Web List Editor as directed in the ComplexWebListEditor.FindPropertyEditor method description. To apply custom settings to an ASPxGridListEditor's column, handle the ASPxGridListEditor.CreateCustomGridViewDataColumn and ASPxGridListEditor.CustomizeGridViewDataColumn events. If you need to access a template for displaying cells within the current column, use the ASPxGridListEditor.CreateCustomDataItemTemplate and ASPxGridListEditor.CreateCustomEditItemTemplate events.

    此方法不会影响列表视图的就地编辑器。要自定义这些编辑器,请使用"如何:自定义内置属性编辑器 (ASP.NET)"主题中介绍的解决方案。或者,按照复杂WebListEditor.FindPropertyEditor方法说明中的指示,访问所需的就地Web列表编辑器。要将自定义设置应用于 ASPxGridlist 编辑器的列,请处理 ASPxGridlistEditor.创建自定义网格视图数据列和 ASPxGridlistEditor.自定义网格视图数据列事件。如果需要访问用于显示当前列中的单元格的模板,请使用 ASPxGridListEditor.创建自定义数据项目模板和 ASPxGridListEditor.创建自定义编辑项目模板事件。

    Due to WinForms and ASP.NET platform specifics, View Item and List Editor controls may not be immediately ready for customization after the control is created. Consider handling additional platform-dependent events or using alternative approaches if the customizations above do not have any effect.

    由于 WinForms 和ASP.NET平台细节,在创建控件后,视图项和列表编辑器控件可能不会立即准备好进行自定义。如果上述自定义项没有任何效果,请考虑处理其他与平台相关的事件或使用替代方法。

    • WinForms:

      Handle the System.Windows.Forms.Control

    object's HandleCreated, VisibleChanged or ParentChanged

    • WinForms:
      处理系统.Windows.窗体.控件

      对象的句柄已创建、可见更改或父更改
    • events. You can also handle the Load (or similar) event if the current control type exposes it.

    • 事件。如果当前控件类型公开了"加载"(或类似)事件,也可以处理该事件。
    • ASP.NET:

      Handle the System.Web.UI.Control

    object's Load or Init
    • ASP.NET:

      处理系统.Web.UI.控件

      对象的加载或 Init
    • server-side event. In certain cases, you may need to handle the WebWindow.PagePreRender event. Use the WebWindow.CurrentRequestWindowstatic property to get the current WebWindow object. You can also perform certain customizations on the client side using JavaScript (see Client-Side Functionality Overview).
    • 服务器端事件。在某些情况下,您可能需要处理 WebWindow.pageprein 事件。使用 WebWindow.CurrentRequest 窗口静态属性获取当前 WebWindow 对象。您还可以使用 JavaScript 在客户端执行某些自定义(请参阅客户端功能概述)。

    These additional platform-dependent events indicate the controls' "ready" state: a control has been added to the form controls hierarchy or has been bound to data. Contact us using the Support Center

    if you need additional help to perform customizations.

    这些与平台相关的其他事件指示控件的"就绪"状态:控件已添加到窗体控件层次结构中或已绑定到数据。使用支持中心联系我们如果您需要其他帮助来执行自定义。

  • 相关阅读:
    BZOJ 1098[POI2007]办公楼
    BZOJ 3629[JLOI2014]聪明的燕姿
    BZOJ 1064[NOI2008]假面舞会
    BZOJ 2818GCD
    【五校联考6day2】san
    【五校联考6day2】er
    【五校联考6day2】yi
    【五校联考3day2】B
    【五校联考5day1】序列
    【五校联考3day2】A
  • 原文地址:https://www.cnblogs.com/foreachlife/p/Access-Editor-Settings.html
Copyright © 2011-2022 走看看