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

效果:

在这里插入图片描述

相关内容

热门资讯

十分钟开挂!微乐小程序黑科技,... 十分钟开挂!微乐小程序黑科技,微乐自建房怎么提高运气(开挂)一直真的是有挂(2026)1、微乐小程序...
网友热议!德普软件(透视)德普... 您好,德普之星私人局透视这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多...
透视插件!微乐建房辅助工具免费... 透视插件!微乐建房辅助工具免费入口,微乐小程序黑科技,经验教程(有挂修改器)-哔哩哔哩1)微乐建房辅...
三分钟神器!微乐小程序免费黑科... 三分钟神器!微乐小程序免费黑科技,微乐小程序自建房透视(开挂)好像是有挂(2026)1)微乐小程序免...
据公告内容!aapoker透视... 据公告内容!aapoker透视怎么用(透视)hhpkoer辅助器视频-一贯有挂(哔哩哔哩)1、玩家可...
截至目前!微信微乐辅助器免费安... 截至目前!微信微乐辅助器免费安装,微乐小程序免费黑科技,练习教程(有挂修改器)-哔哩哔哩1、下载好微...
5分钟脚本!微乐小程序免费黑科... 5分钟脚本!微乐小程序免费黑科技,微信微乐辅助(开挂)果然有挂(2026)1、全新机制【微乐小程序免...
透视软件!德普之星辅助工具如何... 透视软件!德普之星辅助工具如何打开(透视)德普之星辅助软件-一贯真的是有挂(哔哩哔哩)1、许多玩家不...
透视肯定!微乐广西小程序脚本,... 透视肯定!微乐广西小程序脚本,微乐小程序黑科技,烘培教程(有挂辅助器)-哔哩哔哩1、微乐广西小程序脚...
第五分钟开挂!微乐小程序免费黑... 第五分钟开挂!微乐小程序免费黑科技,微信小程序微乐陕西挖坑(开挂)切实真的是有挂(2026)1)微乐...