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

效果:

在这里插入图片描述

相关内容

热门资讯

第4分钟辅助(潇湘游辅助)总是... 第4分钟辅助(潇湘游辅助)总是是真的有挂(详细辅助攻略教程);1、潇湘游辅助ai辅助优化,潇湘游辅助...
透视脚本!wepoker私人局... 透视脚本!wepoker私人局可以透视,白金岛手游放炮罚怎么开挂,2025新版教程(有挂攻略)1、每...
透视中牌率!广东闲来辅助神器,... 透视中牌率!广东闲来辅助神器,南宁友乐辅助,AI教程(有挂攻略);大神普及一款德州ai内幕,确定了广...
带你了解“哥哥打大a微信小程序... 带你了解“哥哥打大a微信小程序作弊”一直是有挂(辅助挂)详细辅助规律教程是一种具有地方特色的麻将游戏...
第6分钟辅助!来来拼十辅助(辅... 第6分钟辅助!来来拼十辅助(辅助挂)原生真的是有挂(详细辅助AA德州教程)是一款可以让一直输的玩家,...
第七分钟辅助(中至鹰潭脚本)果... 第七分钟辅助(中至鹰潭脚本)果然真的有挂(详细辅助德州教程)一、中至鹰潭脚本AI软件牌型概率发牌机制...
透视能赢!wepoker私人局... 透视能赢!wepoker私人局透视插件,传送屋软件辅助,AI教程(有挂辅助)1、很好的工具软件,可以...
透视了解!星悦广东游戏辅助软件... 透视了解!星悦广东游戏辅助软件,开心茶苑13道辅助,透明挂教程(有挂软件)1、许多玩家不知道星悦广东...
一分钟带你了解“新道游游戏辅助... 一分钟带你了解“新道游游戏辅助器免费版”一直是真的有挂(辅助挂)详细辅助德州教程1、玩家可以在软件透...
第9分钟辅助!拱趴游戏攻略(辅... 第9分钟辅助!拱趴游戏攻略(辅助挂)原本存在有挂(详细辅助2025新版总结)1.拱趴游戏攻略 ai辅...