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

效果:

在这里插入图片描述

相关内容

热门资讯

讲义辅助!八闽十三水破解版辅助... 讲义辅助!八闽十三水破解版辅助(辅助挂)总是确实有辅助工具(有挂工具)该软件可以轻松地帮助玩家将八闽...
课程辅助!功夫川麻老是输什么情... 课程辅助!功夫川麻老是输什么情况(辅助挂)都是是真的有辅助app(有挂实锤)1、功夫川麻老是输什么情...
绝活儿辅助!常州茶苑app辅助... 绝活儿辅助!常州茶苑app辅助软件(辅助挂)其实存在有辅助神器(有挂神器)1、常州茶苑app辅助软件...
练习辅助!方片十三张外g挂(辅... 练习辅助!方片十三张外g挂(辅助挂)确实真的是有辅助挂(真实有挂)运方片十三张外g挂辅助工具,进入游...
学习辅助!微信闲来神器软件下载... 学习辅助!微信闲来神器软件下载(辅助挂)一直是有辅助工具(有挂攻略)亲,关键说明,微信闲来神器软件下...
窍门辅助!金虎爷科技(辅助挂)... 窍门辅助!金虎爷科技(辅助挂)竟然真的有辅助器(有挂教程)1、金虎爷科技脚本辅助下载、金虎爷科技免费...
窍要辅助!天道辅助器使用教程(... 窍要辅助!天道辅助器使用教程(辅助挂)一直是真的有辅助软件(有挂讲解)1、完成天道辅助器使用教程有辅...
手筋辅助!福建兄弟13水辅助(... 您好,福建兄弟13水辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
妙招辅助!多乐手游辅助(辅助挂... 妙招辅助!多乐手游辅助(辅助挂)果然是真的有辅助器(有挂详细)1、该软件可以轻松地帮助玩家将多乐手游...
妙招辅助!边锋老友辅助(辅助挂... 妙招辅助!边锋老友辅助(辅助挂)确实真的有辅助脚本(有挂秘诀)1、在边锋老友辅助插件功能辅助器技巧中...