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

效果:

在这里插入图片描述

相关内容

热门资讯

玩家爆料!广东雀神智能插件辅助... 玩家爆料!广东雀神智能插件辅助脚本,We poker辅助器下载,第三方教程(有挂工具)-哔哩哔哩;详...
一分钟揭秘!琼崖辅助软件,大菠... 一分钟揭秘!琼崖辅助软件,大菠萝789辅助器下载,高科技教程(有挂教学)-哔哩哔哩;琼崖辅助软件软件...
我来教大家!小闲川南手游辅助器... 我来教大家!小闲川南手游辅助器,德州透视插件,科技教程(竟然有挂)-哔哩哔哩;1、让任何用户在无需A...
最新研发!四川皮皮辅助,wep... 最新研发!四川皮皮辅助,wepoker私人局透视,曝光教程(的确有挂)-哔哩哔哩;AI辅助机器人普及...
玩家必看科普!微信微乐辅助器下... 玩家必看科普!微信微乐辅助器下载,wepoker亲友圈有用吗,揭秘教程(有挂存在)-哔哩哔哩是一款可...
研究成果!微信小程序雀神广东智... 【福星临门,好运相随】;研究成果!微信小程序雀神广东智能辅助,wepoker辅助器如何使用,解说技巧...
大神推荐!奇迹思维辅助,wep... 大神推荐!奇迹思维辅助,wepoker怎么提高运气,德州论坛(真的有挂)-哔哩哔哩;一、奇迹思维辅助...
重大来袭!花花生活圈开挂,哈糖... 重大来袭!花花生活圈开挂,哈糖大菠萝软件下载,wepoke教程(揭秘有挂)-哔哩哔哩;1、德州花花生...
最新研发!来几局是正规平台吗,... 最新研发!来几局是正规平台吗,哈糖大菠萝能开挂吗,技巧教程(有挂辅助)-哔哩哔哩;小薇(透视辅助)致...
玩家爆料!悟空大厅辅助器,we... 玩家爆料!悟空大厅辅助器,we poker辅助器,2025版教程(存在有挂)-哔哩哔哩是一款可以让一...