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

效果:

在这里插入图片描述

相关内容

热门资讯

第十分钟了解!聚星扑克有挂(辅... 您好,聚星扑克有挂这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
透视好牌!wejoker私人辅... 透视好牌!wejoker私人辅助软件,开心赢三张自建房有挂,技巧教程(了解有挂)-哔哩哔哩该软件可以...
透视透视!hhpoker真能买... 透视透视!hhpoker真能买到挂(透视)底牌透视挂辅助插件(可靠开挂辅助软件教程)-哔哩哔哩;hh...
九分钟了解!约战大同麻将有挂(... 九分钟了解!约战大同麻将有挂(辅助挂)总是真的有挂(专业辅助大神讲解)-哔哩哔哩;运约战大同麻将有挂...
透视ai代打!hhpoker透... 透视ai代打!hhpoker透视脚本视频,哈糖大菠萝可以让系统发好牌,AI教程(确实有挂)-哔哩哔哩...
透视中牌率!wepoker透视... 您好,wepoker透视最简单三个步骤这款游戏可以开挂的,确实是有挂的,需要了解加微【1367043...
十分钟了解!新广西老友麻将有挂... 十分钟了解!新广西老友麻将有挂的(辅助挂)最初是真的有挂(专业辅助安装教程)-哔哩哔哩;十分钟了解!...
透视软件!wepoker新号好... 透视软件!wepoker新号好一点,中至上饶辅助器,2025新版技巧(有挂秘诀)-哔哩哔哩1)中至上...
透视存在!wepoker游戏安... 【福星临门,好运相随】;透视存在!wepoker游戏安装教程(透视)底牌透视挂辅助系统(可靠开挂辅助...
第一分钟了解!心悦踢坑有挂(辅... 第一分钟了解!心悦踢坑有挂(辅助挂)原先真的是有挂(专业辅助揭秘攻略)-哔哩哔哩,心悦踢坑有挂是用手...