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

效果:

在这里插入图片描述

相关内容

热门资讯

受玩家影响!老友广东插件软件,... 受玩家影响!老友广东插件软件,好像存在有辅助下载(新版有挂)-哔哩哔哩1、游戏颠覆性的策略玩法,独创...
教学辅助挂!pokemmo脚本... 教学辅助挂!pokemmo脚本辅助器,微信决胜游戏辅助,手册辅助教程(有挂规律)-哔哩哔哩1、完成微...
连日来!洞庭茶苑辅助,切实是真... 连日来!洞庭茶苑辅助,切实是真的辅助器(有挂讲解)-哔哩哔哩1、很好的工具软件,可以解锁游戏的洞庭茶...
有消息称!wepoker安装教... 有消息称!wepoker安装教程,传送屋辅助k,大纲辅助挂(真的有挂)-哔哩哔哩1、wepoker安...
事发当天!奇迹陕西三代辅助器免... 事发当天!奇迹陕西三代辅助器免费,本来是真的辅助平台(有挂攻略)-哔哩哔哩1、事发当天!奇迹陕西三代...
透视数据!哈糖大菠萝免费辅助器... 透视数据!哈糖大菠萝免费辅助器,全民奇迹脚本,操作辅助技巧(有挂头条)-哔哩哔哩1、哈糖大菠萝免费辅...
据相关数据显示!边锋老友圈怎么... 据相关数据显示!边锋老友圈怎么开辅助,原来是真的辅助神器(有挂教学)-哔哩哔哩亲,关键说明,边锋老友...
2026版软件!拱趴大菠萝万能... 2026版软件!拱趴大菠萝万能挂,丽水都莱辅助软件,绝活儿辅助插件(今日头条)-哔哩哔哩1、玩家可以...
更值得关注的是!途游四川辅助器... 更值得关注的是!途游四川辅助器是真的吗,一贯存在有辅助工具(有挂方法)-哔哩哔哩1、打开软件启动之后...
目前来看!pokemmo手机版... 目前来看!pokemmo手机版脚本,微乐小程序微乐家乡辅助器,要领辅助app(新版有挂)-哔哩哔哩1...