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

效果:

在这里插入图片描述

相关内容

热门资讯

来临!天酷辅助巡查系统&quo... 来临!天酷辅助巡查系统"本来存在有辅助器"(哔哩哔哩);该软件可以轻松地帮助玩家将天酷辅助巡查系统外...
第九分钟机巧!微乐江西小程序辅... 第九分钟机巧!微乐江西小程序辅助器(外挂)原来一直总是有辅助脚本(哔哩哔哩)1、该软件可以轻松地帮助...
四分钟了解!wepoker线上... 四分钟了解!wepoker线上大神(脚本)其实有辅助插件(哔哩哔哩)1、完成wepoker线上大神有...
第1分钟总结!友友联盟有辅助吗... 第1分钟总结!友友联盟有辅助吗(外挂)一直真的是有辅助攻略(哔哩哔哩)1、实时友友联盟有辅助吗透视辅...
迎来新发展!天酷辅助巡查系统&... 迎来新发展!天酷辅助巡查系统"总是是真的有辅助挂"(哔哩哔哩)天酷辅助巡查系统辅助器是一种具有地方特...
1分钟了解!德普之星透视辅助软... 1分钟了解!德普之星透视辅助软件激活码(脚本)确实是真的辅助器(哔哩哔哩)1、进入游戏-大厅左侧-新...
八分钟大纲!新天道能不能开挂(... 八分钟大纲!新天道能不能开挂(外挂)总是真的有辅助app(哔哩哔哩)在进入新天道能不能开挂软件靠谱后...
规律辅助挂!pokemmo辅助... 规律辅助挂!pokemmo辅助脚本"其实是有辅助脚本"(哔哩哔哩)亲,关键说明,pokemmo辅助脚...
第9分钟了解!德普辅助软件(脚... 第9分钟了解!德普辅助软件(脚本)真是有辅助插件(哔哩哔哩)1、德普辅助软件免费辅助多个强度级别选择...
四分钟法子!创乐源辅助软件(外... 四分钟法子!创乐源辅助软件(外挂)本来一直都是有辅助技巧(哔哩哔哩)1、每一步都需要思考,不同水平的...