wpf 实现DataGrid的表格嵌套
创始人
2025-01-10 06:04:18
0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using NavTest.Eneities; using NavTest.Service.Ioc; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows.Controls; using System.Windows.Media;  namespace NavTest.ViewModels {     public partial class Page5ViewModel : ObservableObject, ISingleton     {         private readonly PLCModels pLCModelsIoc;          public Page5ViewModel(PLCModels pLCModelsIoc)         {             this.pLCModelsIoc = pLCModelsIoc;             this.PLCModels = pLCModelsIoc.pLCModels;             MyBrush = new SolidColorBrush(Colors.Red);              for (int i = 0; i < 50; i++)             {                 MyStudents.Add(                     new()                     {                         Id = i,                         Age = $"{i + 10}",                         Name = $"Name{i + 5}",                         MyCourse = new()                         {                             new Course()                             {                                 CourseName = "语文",                                 Teacher = "张老师",                                 Score = i + 60,                                 Classroom = $"教室{i}"                             },                             new Course()                             {                                 CourseName = "英语",                                 Teacher = "李老师",                                 Score = i + 61,                                 Classroom = $"教室{i}"                             }                             ,                             new Course()                             {                                 CourseName = "数学",                                 Teacher = "张老师",                                 Score = i + 60,                                 Classroom = $"教室{i}"                             }                             ,                             new Course()                             {                                 CourseName = "语文",                                 Teacher = "张老师",                                 Score = i + 60,                                 Classroom = $"教室{i}"                             }                             ,                             new Course()                             {                                 CourseName = "语文",                                 Teacher = "张老师",                                 Score = i + 60,                                 Classroom = $"教室{i}"                             }                         }                     }                 );             }         }          [ObservableProperty]         private ObservableCollection pLCModels;          [ObservableProperty]         private Brush myBrush;          [ObservableProperty]         private List myStudents = new();          [ObservableProperty]         private int detailInex;          [RelayCommand]         public void Detail(DataGrid dataGrid)          {             DataGridRow dataGridRow = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(DetailInex);             if (dataGridRow.DetailsVisibility == System.Windows.Visibility.Visible)             {                 dataGridRow.DetailsVisibility = System.Windows.Visibility.Collapsed;             }             else             {                 dataGridRow.DetailsVisibility = System.Windows.Visibility.Visible;             }         }     } }  
    public class Student     {         public int Id { get; set; }         public string? Name { get; set; }         public string? Description { get; set; }         public string? Age { get; set; }         public List? MyCourse { get; set; }     } 
    public class Course     {         public string? CourseName { get; set; }         public string? Teacher { get; set; }         public int? Score { get; set; }         public string? Classroom { get; set; }     } 

效果:

在这里插入图片描述

相关内容

热门资讯

Postman、Apifox、... Postman、Apifox、Apipost都是流行的API接口管理工具,它们各自具有...
【14】Github Copi... 环境搭建这里以Visual Studio Code为例,安装好vs codeÿ...
【Java EE】统一功能返回 一、拦截器1.1 拦截器的作用在对于数据库进行增删查改的时候,如果当前页面不检查用户是...
线性代数:多个随机变量相加的方... 对于多个随机变量相加的方差,我们可以按照独立和不独立的情况进行讨论。1. 独立情况下的...
六分钟了解(gg扑克)软件透明... 六分钟了解(gg扑克)软件透明挂(gg扑克)透明挂辅助器(2023已更新)(哔哩哔哩);小薇(透视辅...
黑科技辅助挂《wepOKE》软... 黑科技辅助挂《wepOKE》软件透明挂!(透明挂)软件科技(2022已更新)(哔哩哔哩)是一款可以让...
技能 | postman接口测... 哈喽小伙伴们大家好!今天来给大家分享一款轻量级,高效好用的接口测试工具-postman.Postma...
玩家交流《微扑克辅助插件》微扑... 玩家交流《微扑克辅助插件》微扑克代打外挂辅助器挂(哔哩哔哩);微扑克软件透明挂是一个全新上线的赚钱平...
教学盘点!微扑克专用辅助软件(... 您好,微扑克这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中...
一分钟揭秘!(微扑克)外挂辅助... 一分钟揭秘!(微扑克)外挂辅助器插件挂!(透视)详细教程(2025已更新)(哔哩哔哩)是一款可以让一...