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)辅助插件:进一步探索辅助...
分享一款!微乐小程序自建房辅助... 分享一款!微乐小程序自建房辅助!微乐富足和靠谱吗(果然真的是有辅助技巧)暗藏猫腻,小编详细说明破解器...
实测揭晓!微乐小程序自建房辅助... 实测揭晓!微乐小程序自建房辅助!微信小程序微乐辅助器ios(本来有辅助app)透视方法中分为三种模型...
科普攻略!微乐小程序辅助工具!... 科普攻略!微乐小程序辅助工具!微信微乐辅助器使用教程(总是真的是有辅助插件)亲,关键说明,透视脚本安...
免费测试版!微乐小程序自建房辅... 免费测试版!微乐小程序自建房辅助!微乐麻将自建房app(都是真的是有辅助软件)1、很好的工具软件,可...
每日必看教程!微乐小程序自建房... 每日必看教程!微乐小程序自建房辅助!微乐春天小程序辅助(一直真的有辅助器)1、很好的工具软件,可以解...
科技通报!微乐小程序自建房辅助... 科技通报!微乐小程序自建房辅助!微乐家乡app辅助器(其实有辅助插件)1、打开软件启动之后找到中间准...
必备教程!微乐小程序自建房辅助... 必备教程!微乐小程序自建房辅助!微信小程序四川微乐脚本(总是有辅助工具)1、金币登录送、破产送、升级...
信息共享!微乐小程序辅助工具!... 信息共享!微乐小程序辅助工具!微信小程序游戏辅助器(果然是有辅助脚本)1、下载好透视辅助下载之后点击...