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

效果:

在这里插入图片描述

相关内容

热门资讯

五分钟了解!杭州都莱挂(辅助挂... 五分钟了解!杭州都莱挂(辅助挂)详细透视开挂辅助教你攻略(切实有挂)-哔哩哔哩;亲真的是有正版授权,...
2分钟了解!传送屋激k万能辅助... 您好,传送屋激k万能辅助器这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...
第十分钟了解!开心泉州辅助器a... 第十分钟了解!开心泉州辅助器app下载(辅助挂)详细透视开挂辅助第三方教程(一直是有挂)-哔哩哔哩;...
9分钟了解!闲逸辅助器(辅助挂... 9分钟了解!闲逸辅助器(辅助挂)详细透视开挂辅助2025新版教程(切实存在有挂)-哔哩哔哩;大家肯定...
9分钟了解!大唐山西辅助(辅助... 9分钟了解!大唐山西辅助(辅助挂)详细透视开挂辅助黑科技教程(一直真的是有挂)-哔哩哔哩;超受欢迎的...
第4分钟了解!兴动互娱辅助设置... 您好:兴动互娱辅助设置步骤详解这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
第7分钟了解!凑一桌游戏软件下... 第7分钟了解!凑一桌游戏软件下载辅助(辅助挂)详细透视开挂辅助可靠教程(好像真的是有挂)-哔哩哔哩;...
六分钟了解!微信小程序万能修改... 六分钟了解!微信小程序万能修改器(辅助挂)详细透视开挂辅助技巧教程(真是是真的挂)-哔哩哔哩是一款可...
2分钟了解!四川游戏家园通用辅... 【福星临门,好运相随】;2分钟了解!四川游戏家园通用辅助(辅助挂)详细透视开挂辅助详细教程(果然是有...
第十分钟了解!枫叶辅助官网(辅... 第十分钟了解!枫叶辅助官网(辅助挂)详细透视开挂辅助攻略方法(一直是真的挂)-哔哩哔哩;枫叶辅助官网...