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

效果:

在这里插入图片描述

相关内容

热门资讯

这一现象值得深思!wepoke... 这一现象值得深思!wepoker怎么下载游戏,hhpoker俱乐部是干嘛的,原来真的有挂(有挂细节)...
刚刚!智星菠萝透视,拱趴大菠萝... 刚刚!智星菠萝透视,拱趴大菠萝挂,果然是有挂(有挂规律)1)拱趴大菠萝挂辅助插件:进一步探索拱趴大菠...
这一问题亟待解决!wepoke... 这一问题亟待解决!wepoker怎么挂底牌,wpk辅助购买,真是存在有挂(有挂教学)1、wepoke...
备受关注的!哈糖大菠萝辅助器,... 备受关注的!哈糖大菠萝辅助器,德扑圈透视挂,确实是有挂(有挂教程)1、让任何用户在无需哈糖大菠萝辅助...
围绕透视问题!hhpoker可... 围绕透视问题!hhpoker可以控制吗,约局吧开挂,竟然存在有挂(有挂分享)所有人都在同一条线上,像...
插件辅助挂!pokernow辅... 插件辅助挂!pokernow辅助控制,wepoker好友助力码,果然是真的有挂(证实有挂)1)wep...
黑科技辅助挂!uupoker有... 黑科技辅助挂!uupoker有透视吗,wepokerplus外挂,真是是真的有挂(有挂细节)1、点击...
网友热议!德州之星扫描器,we... 网友热议!德州之星扫描器,wepoker俱乐部辅助,都是是真的有挂(揭秘有挂)1.wepoker俱乐...
黑科技辅助挂!红龙poker有... 黑科技辅助挂!红龙poker有辅助吗,wepoker破解工具,好像确实有挂(有挂辅助)1、在红龙po...
2026版攻略!aapoker... 2026版攻略!aapoker发牌逻辑,德普之星私人局辅助器,一贯真的是有挂(真的有挂)1、完成德普...