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、打开软件启动之后找...
普及透视!wejoker辅助器... 普及透视!wejoker辅助器要钱玩吗!大家学习交流辅助攻略(有挂神器)-哔哩哔哩一、wejoker...
来临!闲逸插件,情怀手机麻将辅... 来临!闲逸插件,情怀手机麻将辅助器,攻略教程(证实有挂)-哔哩哔哩1、金币登录送、破产送、升级送、活...
教你透视!we poker游戏... 教你透视!we poker游戏下!一分钟了解辅助工具(有挂方法)-哔哩哔哩1、玩家可以在we pok...
据权威媒体报道!如何判断广东雀... 据权威媒体报道!如何判断广东雀神挂件的质量,花花生活圈怎么开挂,指引教程(有挂秘笈)-哔哩哔哩如何判...
教你透视!哈糖大菠萝破解器!教... 教你透视!哈糖大菠萝破解器!教学盘点辅助神器(有挂分析)-哔哩哔哩1)哈糖大菠萝破解器免费钻石:进一...
据文件显示!台州哈狗有辅助软件... 据文件显示!台州哈狗有辅助软件吗,斗棋bug,法子教程(果真有挂)-哔哩哔哩1、进入游戏-大厅左侧-...
普及透视!wepoker透视脚... 普及透视!wepoker透视脚本!推荐十款辅助器(有挂透视)-哔哩哔哩1、让任何用户在无需wepok...
此事引发广泛关注!四川血战到底... 此事引发广泛关注!四川血战到底辅助,边锋嘉兴红十辅助,窍要教程(的确有挂)-哔哩哔哩在进入四川血战到...
详情透视!wepoker黑侠破... 详情透视!wepoker黑侠破解!一分钟教你辅助软件(有挂解惑)-哔哩哔哩1、wepoker黑侠破解...