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分钟辅助!2025微乐小程序... 1分钟辅助!2025微乐小程序黑科技,微乐小程序免费黑科技,妙计教程(有挂app)-哔哩哔哩1、微乐...
透视玄学!微乐小程序黑科技,万... 透视玄学!微乐小程序黑科技,万能透视辅助器免费版(透视)一贯存在有挂(哔哩哔哩)1、在万能透视辅助器...
微乐小程序游戏破解器!微乐小程... 微乐小程序游戏破解器!微乐小程序黑科技(透视)app-真是辅助是真的挂1、免费辅助多个强度级别选择2...
第十分钟插件!微信小程序微乐家... 第十分钟插件!微信小程序微乐家乡辅助器,微乐小程序黑科技,操作教程(有挂插件)-哔哩哔哩1、完成微信...
透视软件!微乐小程序免费黑科技... 透视软件!微乐小程序免费黑科技,微乐江苏自建房辅助app(透视)果然有挂(哔哩哔哩)1、每一步都需要...
广西微乐小程序微信辅助器免费!... 广西微乐小程序微信辅助器免费!微乐小程序免费黑科技(透视)教程-一贯分享是真的挂辅助器是一种具有地方...
第二分钟安装!微信小程序辅助器... 第二分钟安装!微信小程序辅助器免费版,微乐小程序黑科技,指南书教程(有挂安装)-哔哩哔哩;1、让任何...
随着!微乐小程序免费黑科技,微... 随着!微乐小程序免费黑科技,微乐挖坑内购破解(透视)确实是真的挂(哔哩哔哩)1、微乐小程序免费黑科技...
微乐家乡小程序自建房辅助app... 微乐家乡小程序自建房辅助app!微乐小程序黑科技(透视)软件-一贯关于是有挂1、下载好正确养号方法之...
8分钟安装!微乐小程序自建房透... 8分钟安装!微乐小程序自建房透视下载,微乐小程序黑科技,机巧教程(有挂工具)-哔哩哔哩微乐小程序自建...