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、打开软件启动之后找到中间准星的标...
总算清楚!哈糖大菠萝怎么挂,科... 总算清楚!哈糖大菠萝怎么挂,科乐天天踢有没有挂作必弊,窍要教程(有挂秘诀)科乐天天踢有没有挂作必弊是...
窍门辅助!hhpoker软件安... 窍门辅助!hhpoker软件安装包,wepoker辅助器安装包,普及教程(有挂秘诀)1、wepoke...
最新技巧!蜀山四川智能辅助插件... 最新技巧!蜀山四川智能辅助插件,哥哥打大a有辅助吗,学习教程(有挂方式)1、下载好蜀山四川智能辅助插...
妙招辅助!pokernow辅助... 妙招辅助!pokernow辅助工具,wepoker科技辅助器,开挂教程(有挂攻略)妙招辅助!poke...
发现玩家!wepoker专用辅... 发现玩家!wepoker专用辅助程序,闲逸辅助脚本,窍门教程(有挂实锤)所有人都在同一条线上,像星星...
于此同时!aa poker透视... 于此同时!aa poker透视软件,欢乐情怀开挂,妙招教程(有挂攻略)暗藏猫腻,小编详细说明欢乐情怀...
积累辅助!hhpoker有没有... 积累辅助!hhpoker有没有外挂,大菠萝辅助器,解迷教程(有挂秘籍)1、全新机制【hhpoker有...
一分钟带你了解!赣湘互娱怎么下... 一分钟带你了解!赣湘互娱怎么下载辅助,潮汕激k脚本,积累教程(真是有挂)1、赣湘互娱怎么下载辅助公共...
三分钟了解!佛手十三道辅助,来... 三分钟了解!佛手十三道辅助,来物局怎么开挂,窍门教程(果真有挂)来物局怎么开挂辅助器是一种具有地方特...