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

效果:

在这里插入图片描述

相关内容

热门资讯

一分钟教会你!阿当比鸡有辅助吗... 一分钟教会你!阿当比鸡有辅助吗,众亿辅助(有挂开挂辅助器);无需打开直接搜索微信(136704302...
透明规律!微信小程序微乐房间怎... 透明规律!微信小程序微乐房间怎么开挂,九酷众游辅助,详细教程(有挂开挂辅助挂);无需打开直接搜索加薇...
第五攻略!新超凡辅助器,微乐广... 第五攻略!新超凡辅助器,微乐广西自建房免费黑科技下载(有挂开挂辅助平台);无需打开直接搜索打开薇:1...
安装程序教程!福州十八扑破解,... 您好:福州十八扑破解这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特...
透明有挂!pokemmo辅助器... 透明有挂!pokemmo辅助器手机版下载,天酷大厅辅助,专业教程(有挂开挂辅助平台) 了解更多开挂安...
第2讲义!雀友会广东潮汕麻雀,... 第2讲义!雀友会广东潮汕麻雀,雀神广东智能插件(有挂开挂辅助软件);打开点击测试直接进入微信(136...
我来教教大家!福建13水插件,... 我来教教大家!福建13水插件,小闲川南辅助(有挂开挂辅助脚本);无需打开直接搜索加薇13670430...
透明科技!广东雀神智能插件免费... 透明科技!广东雀神智能插件免费,天酷辅助巡查系统,黑科技教程(有挂开挂辅助工具);无需打开直接搜索薇...
六指南书!海贝之城正版辅助,微... 微乐自建房辅助工具官网是一款专注玩家量身打造的游戏记牌类型软件,在微乐自建房辅助工具官网这款游戏中我...
科技通报!网上微乐家乡微信版辅... 科技通报!网上微乐家乡微信版辅助器,菜鸟黑桃a3辅助(有挂开挂辅助安装)1、下载安装好网上微乐家乡微...