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,黑科技教程(有挂技巧);玩家必备必赢加哟《13...
六分钟辅助!传送屋辅助器(辅助... 六分钟辅助!传送屋辅助器(辅助挂)一贯有挂(详细辅助高科技教程)1、许多玩家不知道传送屋辅助器辅助软...
八分钟辅助(牵手游戏辅助)真是... 八分钟辅助(牵手游戏辅助)真是真的是有挂(详细辅助2025新版总结)1、用户打开应用后不用登录就可以...
科技揭秘“九酷众游软件”切实真... 科技揭秘“九酷众游软件”切实真的是有挂(辅助挂)详细辅助力荐教程1、系统规律教程、辅助透视等服务,为...
透视计算!微信小程序哥哥打大a... 1、透视计算!微信小程序哥哥打大a辅助,金州水鱼脚本,教你教程(有挂软件);详细教程。2、微信小程序...
6分钟辅助!财神十三张安装工具... 6分钟辅助!财神十三张安装工具(辅助挂)从前是真的有挂(详细辅助2025新版技巧)1.财神十三张安装...
两分钟辅助(家乡大二辅助免费)... 两分钟辅助(家乡大二辅助免费)原来真的是有挂(详细辅助曝光教程);运家乡大二辅助免费辅助工具,进入游...
透视总结!战神辅助器下载,决战... 透视总结!战神辅助器下载,决战卡五星辅助软件,系统教程(有挂软件)准备好在决战卡五星辅助软件 ia的...
分享给玩家“樱花之盛辅助器”果... 分享给玩家“樱花之盛辅助器”果然是真的有挂(辅助挂)详细辅助科技教程1)辅助挂:进一步探索辅助透视大...
8分钟辅助!拼十辅助器(辅助挂... 8分钟辅助!拼十辅助器(辅助挂)确实存在有挂(详细辅助软件教程);无聊就玩这款拼十辅助器真的有辅助,...