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

效果:

在这里插入图片描述

相关内容

热门资讯

透视详情!wejoker内置辅... 透视详情!wejoker内置辅助,wepoker免费钻石-其实有辅助教程(哔哩哔哩)1、让任何用户在...
透视推荐!wpk德州局透视,w... 透视推荐!wpk德州局透视,wpk可以作弊吗-原来是有辅助攻略(哔哩哔哩)1、游戏颠覆性的策略玩法,...
透视详细!智星德州插件,pok... 透视详细!智星德州插件,pokemmo辅助官网-好像真的有辅助脚本(哔哩哔哩)1、玩家可以在poke...
透视详细!wpk透视怎么安装,... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
透视教你!德普之星的辅助工具介... 透视教你!德普之星的辅助工具介绍,德普辅助软件-一贯一直都是有辅助教程(哔哩哔哩)小薇(辅助器软件下...
透视曝光!wepoker祈福有... 透视曝光!wepoker祈福有用吗,wepoker透视脚本视频-总是是真的有辅助软件(哔哩哔哩)ep...
透视揭幕!pokerworld... 透视揭幕!pokerworld破解版下载,poker world辅助器-其实一直都是有辅助方法(哔哩...
据统计!开心泉州免费辅助器!竟... 据统计!开心泉州免费辅助器!竟然存在有辅助神器(有挂详细)-哔哩哔哩1、玩家可以在开心泉州免费辅助器...
重大科普!wepoker轻量版... 重大科普!wepoker轻量版有透视吗,约局吧德州透视,开挂教程(有挂透视)-哔哩哔哩1、wepok...
有玩家发现!逗娱碰胡辅助器!确... 有玩家发现!逗娱碰胡辅助器!确实是有辅助安装(确实有挂)-哔哩哔哩逗娱碰胡辅助器透视方法中分为三种模...