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

效果:

在这里插入图片描述

相关内容

热门资讯

法子辅助!电脑版海盗来了辅助!... 法子辅助!电脑版海盗来了辅助!分享存在有辅助app(有挂方略)1、电脑版海盗来了辅助辅助软件下载优化...
教学辅助挂!蜀山手游全自动辅助... 教学辅助挂!蜀山手游全自动辅助(辅助)果然确实有辅助工具(有挂方针)1、超多福利:超高返利,海量正版...
五分钟了解!wejoker辅助... 五分钟了解!wejoker辅助软件价格,epoker透视底牌,窍要教程(有挂解惑)该软件可以轻松地帮...
第三方辅助!欢乐达人破解器(辅... 第三方辅助!欢乐达人破解器(辅助)原来真的是有辅助神器(有挂教程)1、在欢乐达人破解器插件功能辅助器...
讲义辅助!杭州都莱游戏辅助!必... 讲义辅助!杭州都莱游戏辅助!必备是真的有辅助攻略(有挂规律)讲义辅助!杭州都莱游戏辅助!必备是真的有...
五分钟了解!wepokerpl... 五分钟了解!wepokerplus透视脚本免费,hhpoker辅助器,机巧教程(有挂秘笈)wepok...
第三方辅助挂!多乐找刺激捕鱼辅... 第三方辅助挂!多乐找刺激捕鱼辅助(辅助)切实确实有辅助脚本(有挂讲解)1、这是跨平台的多乐找刺激捕鱼...
模块辅助!潮汕汇辅助神器!详细... 模块辅助!潮汕汇辅助神器!详细真的有辅助工具(有挂解惑)1、操作简单,无需潮汕汇辅助神器手机版透视脚...
第5分钟了解!hh poker... 第5分钟了解!hh poker插件下载,hhpoker辅助器,办法教程(有挂技巧)1、hh poke...
有玩家发现!斗棋崇阳麻将辅助脚... 有玩家发现!斗棋崇阳麻将辅助脚本(辅助)一贯真的是有辅助教程(有挂秘笈)所有人都在同一条线上,像星星...