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、神途免费辅助软件公共底牌简单...
七分钟了解!火神微信辅助!都是... 七分钟了解!火神微信辅助!都是是有辅助脚本(有挂细节)-哔哩哔哩1)火神微信辅助有没有挂:进一步探索...
7分钟了解!衢州都莱辅助器是真... 7分钟了解!衢州都莱辅助器是真是假!一贯存在有辅助方法(了解有挂)-哔哩哔哩进入游戏-大厅左侧-新手...
八分钟了解!玄龙辅助下载!竟然... 八分钟了解!玄龙辅助下载!竟然有辅助攻略(确实有挂)-哔哩哔哩运玄龙辅助下载辅助工具,进入游戏界面。...
十分钟了解!科乐天天踢起手好牌... 十分钟了解!科乐天天踢起手好牌!总是存在有辅助方法(确实有挂)-哔哩哔哩1、游戏颠覆性的策略玩法,独...
第一分钟了解!决战加血辅助!一... 第一分钟了解!决战加血辅助!一贯真的有辅助插件(有挂透视)-哔哩哔哩1、决战加血辅助透视辅助软件激活...
两分钟了解!欢聚水鱼科技辅助下... 两分钟了解!欢聚水鱼科技辅助下载!果然一直都是有辅助神器(有挂秘诀)-哔哩哔哩1、让任何用户在无需欢...
4分钟了解!微信小程序雀神挂件... 4分钟了解!微信小程序雀神挂件!真是真的有辅助插件(真的有挂)-哔哩哔哩1、完成微信小程序雀神挂件有...
两分钟了解!新上游通用挂是真的... 两分钟了解!新上游通用挂是真的吗!本来真的有辅助教程(有挂透视)-哔哩哔哩所有人都在同一条线上,像星...
四分钟了解!德州局脚本!一贯真... 四分钟了解!德州局脚本!一贯真的是有辅助神器(有挂细节)-哔哩哔哩1、上手简单,内置详细流程视频教学...