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

效果:

在这里插入图片描述

相关内容

热门资讯

4分钟曝光!斗城麻将微信有没有... 4分钟曝光!斗城麻将微信有没有挂(辅助挂)好像有挂,高科技教程(有挂细节)-哔哩哔哩;1、进入游戏-...
9分钟技巧!多乐找刺激窍门,顺... 9分钟技巧!多乐找刺激窍门,顺欣茶楼软件,竟然有挂(果真有挂)-哔哩哔哩1、完成多乐找刺激窍门的残局...
第九分钟揭露!福建十三水软件开... 第九分钟揭露!福建十三水软件开发(辅助挂)好像存在有挂,软件教程(有挂工具)-哔哩哔哩1、游戏颠覆性...
第1分钟插件!竹简茶馆辅助,新... 第1分钟插件!竹简茶馆辅助,新九方科技,果然存在有挂(有挂详细)-哔哩哔哩1、每一步都需要思考,不同...
第2分钟总结!九九联盟后台可以... 第2分钟总结!九九联盟后台可以操作吗(辅助挂)都是有挂,透牌教程(有挂方式)-哔哩哔哩亲,关键说明,...
八分钟总结!陕西三代二破解(辅... 八分钟总结!陕西三代二破解(辅助挂)一贯存在有挂,规律教程(有挂解密)-哔哩哔哩1、陕西三代二破解透...
七分钟脚本!掌酷天天开心辅助器... 七分钟脚本!掌酷天天开心辅助器,新道游辅助,好像有挂(有挂详细)-哔哩哔哩;1)掌酷天天开心辅助器辅...
第2分钟普及!凑一桌游戏辅助器... 第2分钟普及!凑一桌游戏辅助器怎么安装(辅助挂)都是是有挂,规律教程(有挂秘笈)-哔哩哔哩凑一桌游戏...
第2分钟工具!花花生活圈第三方... 第2分钟工具!花花生活圈第三方工具,赣牌圈小程序破解版,竟然有挂(了解有挂)-哔哩哔哩暗藏猫腻,小编...
5分钟揭露!赣牌圈控制牌型(辅... 5分钟揭露!赣牌圈控制牌型(辅助挂)原来真的有挂,专业教程(发现有挂)-哔哩哔哩赣牌圈控制牌型辅助器...