首页 > 其他分享 >学习012-04-09-01-02 How to: Show a Custom Data-Bound Control in an XAF View (Blazor) - Current Object

学习012-04-09-01-02 How to: Show a Custom Data-Bound Control in an XAF View (Blazor) - Current Object

时间:2025-01-18 18:28:07浏览次数:3  
标签:02 Control 视图 Current MainDemo Department using Blazor View

How to: Show a Custom Data-Bound Control in an XAF View (Blazor) - Current Object Data(如何:在 XAF 视图(Blazor)中显示自定义数据绑定控件 - 当前对象数据)

This article explains how to create a reusable View Item that can work with data supplied by the View’s current object. Before you continue, make sure you are familiar with the tutorial that describes the commonly required steps - How to: Show a Custom Data-Bound Control in an XAF View (Blazor) - External Data .
本文介绍如何创建一个可重用的视图项,该视图项可以处理视图当前对象提供的数据。在继续之前,请确保您熟悉描述常用步骤的教程-如何:在XAF视图中显示自定义数据绑定控件(Blazor)-外部数据。

在这里插入图片描述

Create a Razor Component(创建Razor组件)

In this example, you create a Razor component based on DxAccordion . The new component displays employees assigned to a particular department.
在此示例中,您将创建一个基于DxHanddion的Razor组件。新组件显示分配到特定部门的员工。

To add this component to your project, follow the steps below:
要将此组件添加到您的项目中,请执行以下步骤:

1.In the Solution Explorer, right-click your project’s name and select Add -> New Item from the ensuing context menu.
在解决方案资源管理器中,右键单击项目名称并从随后的上下文菜单中选择Add->New Item。

2.Specify a component name (DepartmentViewer.razor).
指定组件名称(DepartmentViewer. razor)。

3.Add the following code to the created file.
将以下代码添加到创建的文件中。

Razor
@using MainDemo.Module.BusinessObjects;
@using DevExpress.Blazor;


@if (Department == null) {
    <div>No selected department.</div>    
} else {
    <p>Department name: <DxTextBox @bind-Text="@Department.Title" /></p>
    <p>Department head: @Department.DepartmentHead?.FullName</p>
    <p>Department description: @Department.Description</p>
    <DxAccordion ExpandMode="AccordionExpandMode.SingleOrNone"
                style="max-width: 600px"
                AnimationType="LayoutAnimationType.Slide">
        <Items>
            @if(Department.Employees is not null) {
                @foreach(var employee in Department.Employees) {
                    <DxAccordionItem Text="@employee.FullName" @key="employee">
                        <ContentTemplate>
                            <div style="display: flex;">
                                <div style="flex: 1 0 0;">
                                    <div><b>Full name:</b> @employee.FullName</div>
                                    <div><b>Email address:</b> @employee.Email</div>
                                    <div><b>Position:</b> @employee.Position</div>
                                    <div><b>Office:</b> @employee.Department.Office</div>
                                    @if(employee.Manager is not null) {
                                        <div><b>Manager:</b> @employee.Manager.FullName</div>
                                    }
                                </div>
                                <div style="flex: 1 0 0; display: flex; justify-content: end;">
                                    @if(employee.Photo is not null) {
                                        <div style="flex: 1 0 0; display: flex; justify-content: end;">
                                            <img src="@($"data:image/png;base64,{Convert.ToBase64String(employee.Photo)}")"
                                                style="max-width: 300px; max-height: 300px;">
                                        </div>
                                    }
                                </div>
                            </div>
                        </ContentTemplate>
                    </DxAccordionItem>
                }
            }
        </Items>
    </DxAccordion>
}


@code {
    [Parameter] public Department Department { get; set; }
}

The DepartmentViewerModel.SetTitleFromUI method notifies subscribers when a user changes the department’s title.
DepartmentViewerModel.SetTitleFromUI方法在用户更改部门标题时通知订阅者。

4.In the Properties window, set this file’s Build Action to Content.
在属性窗口中,将此文件的构建操作设置为内容。

Create a Custom View Item and its Control(创建自定义视图项及其控件)

Create a custom View Item that implements IComponentContentHolder and returns DepartmentViewerModel in the CreateControlCore method. To do this, follow the steps below:
在CreateControlCore方法中创建实现IComponentContentHolder并返回DepartmentViewerModel的自定义视图项。

1.Add a new file (DepartmentViewerViewItem.cs) to your Blazor project.
将新文件(DepartmentViewerViewItem. cs)添加到Blazor项目中。

2.Add the following code to the created file.
将以下代码添加到创建的文件中。

C#
using  DevExpress.ExpressApp.Blazor ;
using DevExpress.ExpressApp.Blazor.Components;
using DevExpress.ExpressApp.Blazor.Components.Models;
using  DevExpress.ExpressApp.Editors ;
using  DevExpress.ExpressApp.Model ;
using MainDemo.Blazor.Server.Controllers;
using MainDemo.Module.BusinessObjects;
using  Microsoft.AspNetCore.Components ;


namespace MainDemo.Blazor.Server;


public class DepartmentViewerModel : ComponentModelBase {
    public Department Department {
        get => GetPropertyValue<Department>();
        set => SetPropertyValue(value);
    }
    public override Type ComponentType => typeof(DepartmentViewer);
}


public interface IModelDepartmentViewerViewItem : IModelViewItem { }


[ViewItem(typeof(IModelDepartmentViewerViewItem))]
public class DepartmentViewerViewItem : ViewItem, IComponentContentHolder {
    private RenderFragment _componentContent;
    public DepartmentViewerModel ComponentModel { get; private set; }
    public DepartmentViewerViewItem(IModelDepartmentViewerViewItem model, Type objectType) : base(objectType, model.Id) { }
    protected override object CreateControlCore() {
        ComponentModel = new DepartmentViewerModel { Department = View.CurrentObject as Department };
        return ComponentModel;
    }
    public RenderFragment ComponentContent {
        get {
            _componentContent ??= ComponentModelObserver.Create(ComponentModel, ComponentModel.GetComponentContent());
            return _componentContent;
        }
    }
    protected override void OnCurrentObjectChanged() {
        base.OnCurrentObjectChanged();
        if(ComponentModel is not null) {
            ComponentModel.Department = View.CurrentObject as Department;
        }
    }
}

3.Rebuild your solution.
重建您的解决方案。

For more information on how to implement View Items in XAF applications, refer to the following topic: Implement a View Item (WinForms) .
有关如何在XAF应用程序中实现视图项的更多信息,请参阅以下主题:实现视图项(WinForms)。

Change the Default Detail View for the Department List View(更改部门列表视图的默认详细信息视图)

1.In the Blazor application project, double-click the Model.xafml file to start the Model Editor . Right-click the Views node and choose Add | DetailView.
在Blazor应用程序项目中,双击Model. xafml文件以启动模型编辑器。右键单击视图节点并选择添加|DetailView。
在这里插入图片描述

2.Set the Id property to CustomDepartment_DetailView and the ModelClass property to MainDemo.Module.BusinessObjects.Department.
将Id属性设置为CustomDepartment_DetailView,将ModelClass属性设置为MainDemo. Module.BusinessObject.Department。
在这里插入图片描述

3.Right-click the Views | MainDemo.Module.BusinessObjects | CustomDepartment_DetailView | Items node and choose Add… | DepartmentViewerItemView.
右键单击Views|MainDemo. Module.BusinessObjects|CustomDepartment_DetailView|Items节点,然后选择Add…|DepartmentViewerItemView。
在这里插入图片描述

4.Set the Id property to DepartmentViewItem.
将Id属性设置为DepartmentViewItem。

5.Navigate to the Views | MainDemo.Module.BusinessObjects | Department_ListView node. In the DetailView drop-down list, select CustomDepartment_DetailView.
导航到视图|MainDemo. Module.BusinessObjects|Department_ListView节点。在DetailView下拉列表中,选择CustomDepartment_DetailView。
在这里插入图片描述

6.Run the your Blazor application, navigate to the Department List View, open any Detail View, and see the result.
运行Blazor应用程序,导航到部门列表视图,打开任何详细信息视图,然后查看结果。
在这里插入图片描述

标签:02,Control,视图,Current,MainDemo,Department,using,Blazor,View
From: https://blog.csdn.net/thomastang200912_126/article/details/145155529

相关文章

  • 洛谷 P11388 [COCI 2024/2025 #1] 飞跃 / Skokovi
    #[COCI2024/2025#1]飞跃/Skokovi##题目背景译自[COCI2024/2025#1](https://hsin.hr/coci/)T2。$\texttt{5s,0.5G}$。满分为$75$。##题目描述有$n$朵花,此外有一个正整数$k$。第$i$朵花的高度为$a_i$。一开始,Filip在第$1$朵花上。当她在第$i$朵花......
  • 「NOIP2024」 树上查询
    update2024/12/28题目描述给定一棵树,每次询问区间\([l,r]\)的\[\max_{l\lel'\ler'\ler\landr'-l'+1\gek}\text{dep}_{\text{LCA*}(l',r')}\]引理证明先来证两个区间\(\text{LCA}\)的引理:对于\(\text{LCA}\{l,l+1,\dots......
  • 2025.1.1-2025.1.18
    期末周这些天是期末周,考着考着有些科就出了成绩大学的期末考试更加应试,更加简单,要想取得好成绩完全可以靠期末周突击考试很显然,我没有应试的那个态度,复习的很潦草,没什么动力要想取得好绩点,我通过这次期末考试也得到了一些经验:1,往年的习题----很有可能再考2.平......
  • 2025年flask电影院售票系统 程序+论文 可用于计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容选题背景关于电影院售票系统的研究,现有研究主要集中在票务管理系统、在线预订平台以及客户关系管理等方面。尽管国内外已有众多电影院售票系统的开......
  • 2025年flask电子病历管理系统 程序+论文 可用于计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容选题背景关于电子病历管理系统的研究,现有研究主要集中在医疗信息化、数据管理与安全、以及临床决策支持等方面。尽管国内外已有众多电子病历系统的......
  • 20250116 支付宝出现重大事故 有感
    事故20250116下午支付宝直接冲上微博热搜榜首,原因是在2025年01月16日14:40-14:45期间出现大量支付显示“政府补贴”减免字样。最开始我是在小红书上看到的相关内容,只是看到这个图片,心想这肯定是小红书暗广,撇了一眼就划过了。当“支付宝出现重大BUG”出现在微博头条时,才确信此事......
  • THUWC2025题解
    Day1T1构造一个排列,使满足最多的形如\([l,r]\)内单调递增/减。一个简单的线段树优化DP,设状态\(f_{i,0/1}\)即可转移,\(O(n\logn)\)。T2支持往集合中加三维带权点,查询集合中没有任何一维与给出点对应维度相等的最大点权。唐题。一种暴力的想法是三维数点之类的,不太能......
  • [2025.1.18 JavaSE学习]标准I/O流 && 转换流
    标准I/O流System.in:标准输入默认设备:键盘类型:InputStreamSystem.out:标准输出默认设备:显示器类型:PrintStreamSystem.in编译类型为InputStream,而运行类型为BufferedInputStreampublicfinalstaticInputStreamin=null;System.out编译类型为PrintStream,运行类......
  • P9730 [CEOI2023] Grading Server
    这是什么神仙题啊。本题主要思路:优化转移决策,减少dp状态。我们发现减一层盾其实就是给自己加攻击,所以我们将初始生命值(攻击力)\(C_H\)和\(C_G\)重新表示为\(A_1=C_H-f_GS\),\(A_2=C_G-f_HS\),让\(F_1=f_G\),\(F_2=f_H\)。现在的点对就是\((A_1,F_1,A_2,F_......
  • PKUWC2025部分题解
    Day1A注意到,原题等价于构造一个\(a+b\)个点的完全图,使最大独立集\(<a\),且边数最小。很难发现,图必然被划分成\(a-1\)个完全图。据此DP或令\(a-1\)个图点数平均。CDAG上考虑暴力。设\(f_{u,i}\)表示第\(i\)轮在\(u\)是否先手必胜。转移枚举相邻点就好,\(\large......