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; }     } 

效果:

在这里插入图片描述

相关内容

热门资讯

透视线上!微信微乐辅助插件,佛... 透视线上!微信微乐辅助插件,佛手在线大菠萝为什么都输,科技教程(有挂开挂辅助平台);无需打开直接搜索...
第九分钟掌握!辅助软件购买平台... 第九分钟掌握!辅助软件购买平台,广东闲来辅助(有挂开挂辅助下载);无需打开直接搜索加薇1367043...
解密关于!微信大厅辅助软件,战... 解密关于!微信大厅辅助软件,战皇大厅辅助那个可靠(有挂开挂辅助器);无需打开直接搜索薇:136704...
透明辅助!蛮王大厅辅助教程,微... 透明辅助!蛮王大厅辅助教程,微乐广西麻辣辅助,解说技巧(有挂开挂辅助下载);无需打开直接搜索加薇13...
5小时领会!哈局辅助,好友赣南... 5小时领会!哈局辅助,好友赣南新版本辅助(有挂开挂辅助下载);无需打开直接搜索加薇136704302...
重大通报!小松宿松游戏辅助,新... 您好:新九五有没有脚本这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
透视模拟器!万能透视辅助器免费... 您好:万能透视辅助器免费版这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户...
第9刹那了解!山西扣点辅助,天... 第9刹那了解!山西扣点辅助,天天微友辅助器(有挂开挂辅助工具);无需打开直接搜索薇:13670430...
一起来讨论!小程序财神十三脚本... 一起来讨论!小程序财神十三脚本,边锋老友内蒙古辅助(有挂开挂辅助挂)1、下载安装好小程序财神十三脚本...
透视软件!微信小程序微乐陕西挖... 透视软件!微信小程序微乐陕西挖坑辅助,收集微乐小程序游戏破解器,靠谱教程(有挂开挂辅助脚本);无需打...