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有机器人吗中的10万...
玩家爆料!智星菠萝可以辅助吗(... 玩家爆料!智星菠萝可以辅助吗(透视)本来有开挂辅助黑科技;智星菠萝可以辅助吗中的10万兆豆可能无法通...
重大科普!蜀山四川辅助脚本(透... 重大科普!蜀山四川辅助脚本(透视)werplan怎么透视(分享开挂辅助教程)是一款可以让一直输的玩家...
最新技巧!hhpoker辅助器... 最新技巧!hhpoker辅助器视频(透视)真是有开挂辅助器;亲真的是有正版授权,小编(透视辅助软件透...
传递经验!微信老友广东辅助器(... 传递经验!微信老友广东辅助器(透视)hhpoker透视脚本视频(详情开挂辅助脚本);相信小伙伴都知道...
推荐一款!来玩德州破解器(透视... 推荐一款!来玩德州破解器(透视)从前有开挂辅助黑科技;小薇(透视辅助)致您一封信;亲爱来玩德州破解器...
科技通报!微乐小程序辅助器(透... 科技通报!微乐小程序辅助器(透视)德州透视脚本(推荐开挂辅助挂);大家肯定在之前微乐小程序辅助器或者...
科普!wepoker科技辅助器... 科普!wepoker科技辅助器(透视)原本有开挂辅助安装;一、wepoker科技辅助器有挂的是的,亲...
研究成果!潘潘讲故事app有挂... 【福星临门,好运相随】;研究成果!潘潘讲故事app有挂(透视)hhpoker有没有透视挂(解密开挂辅...