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

效果:

在这里插入图片描述

相关内容

热门资讯

做出回应!xpoker辅助神器... 做出回应!xpoker辅助神器,随意玩房卡代理有挂吗,阶段辅助方法(有挂方针)-哔哩哔哩1、上手简单...
日前!东阳四副牌辅助,真是有挂... 日前!东阳四副牌辅助,真是有挂辅助脚本(有挂方式)-哔哩哔哩1、该软件可以轻松地帮助玩家将东阳四副牌...
普及透视!poker mast... 普及透视!poker master辅助,拱趴大菠萝作必弊方法(透视)好像是有辅助方法(哔哩哔哩)1、...
最终!fishpoker透视,... 最终!fishpoker透视,微信小程序中至上饶麻将有挂,指南书辅助攻略(讲解有挂)-哔哩哔哩1、进...
有玩家发现!奇迹手游辅助脚本平... 有玩家发现!奇迹手游辅助脚本平台免费,原来是有辅助器(有挂实锤)-哔哩哔哩1、该软件可以轻松地帮助玩...
解谜透视!红龙poker辅助器... 解谜透视!红龙poker辅助器免费观看,拱趴游戏破解器(透视)原来是真的有辅助插件(哔哩哔哩)1)红...
黑科技技巧!菠萝辅助器免费版的... 黑科技技巧!菠萝辅助器免费版的功能介绍,四川徒有辅助软件,举措辅助技巧(有人有挂)-哔哩哔哩菠萝辅助...
做出回应!游戏辅助制作器,原来... 做出回应!游戏辅助制作器,原来真的有辅助神器(有挂解惑)-哔哩哔哩小薇(辅助器软件下载)致您一封信;...
推荐透视!werplan外卦神... 推荐透视!werplan外卦神器,佛手大菠萝有挂吗(透视)总是是真的有辅助app(哔哩哔哩)推荐透视...
经核实!哈糖大菠萝怎么挂,朋朋... 经核实!哈糖大菠萝怎么挂,朋朋政和辅助器免费在哪里,窍要辅助器(有挂分享)-哔哩哔哩1、玩家可以在朋...