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

效果:

在这里插入图片描述

相关内容

热门资讯

九分钟辅助!wepoker辅助... 九分钟辅助!wepoker辅助器免费,wepoker怎么看牌型,方案教程(有挂方针)wepoker怎...
三分钟辅助!wepoker作弊... 三分钟辅助!wepoker作弊方法,德普之星私人局辅助器,手筋教程(有挂透视)1、德普之星私人局辅助...
第七分钟辅助!智星菠萝有挂吗,... 第七分钟辅助!智星菠萝有挂吗,智星德州可以透视吗,诀窍教程(有挂规律)该软件可以轻松地帮助玩家将智星...
第5分钟辅助!hhpoker作... 第5分钟辅助!hhpoker作弊码,hh poker透视器下载,课程教程(有挂秘笈)1、hh pok...
一分钟辅助!wpk俱乐部有没有... 一分钟辅助!wpk俱乐部有没有辅助,wepoker私人局辅助挂,诀窍教程(有挂解密)1、下载好wpk...
第2分钟辅助!sohoo竞技联... 第2分钟辅助!sohoo竞技联盟辅助器,pokermaster辅助器,手筋教程(有挂神器)1、soh...
第六分钟辅助!htx矩阵wep... 第六分钟辅助!htx矩阵wepoker辅助,hhpkoer辅助挂是真的吗,指南教程(有挂解密)1、游...
第七分钟辅助!哈糖大菠萝可以开... 第七分钟辅助!哈糖大菠萝可以开挂吗,佛手大菠萝有挂吗,技法教程(有挂详情)哈糖大菠萝可以开挂吗脚本下...
3分钟辅助!pokemmo手机... 3分钟辅助!pokemmo手机版透视脚本,xpoker辅助助手,指南书教程(有挂头条)1、pokem...
6分钟辅助!wepoker好友... 6分钟辅助!wepoker好友局透视,wepoker怎么挂底牌,指引教程(有挂攻略)1、wepoke...