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、玩家可以在新道游...
据悉!威信茶馆app插件(辅助... 据悉!威信茶馆app插件(辅助挂)一直真的有挂(正版开挂辅助脚本)-哔哩哔哩1、玩家可以在威信茶馆a...
突发!吉祥填大坑小程序辅助(辅... 突发!吉祥填大坑小程序辅助(辅助挂)其实确实有挂(详细开挂辅助神器)-哔哩哔哩1、吉祥填大坑小程序辅...
最终!奇迹脚本辅助(辅助挂)原... 您好,奇迹脚本辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在...
无独有偶!上饶打炸祈福(辅助挂... 无独有偶!上饶打炸祈福(辅助挂)果然有挂(曝光开挂辅助下载)-哔哩哔哩上饶打炸祈福是一种具有地方特色...
有玩家发现!微乐智能辅助app... 有玩家发现!微乐智能辅助app(辅助挂)一贯有挂(细节开挂辅助插件)-哔哩哔哩1、在微乐智能辅助ap...
日前!广西老友辅助app(辅助... 日前!广西老友辅助app(辅助挂)一贯确实有挂(细节开挂辅助工具)-哔哩哔哩1、上手简单,内置详细流...
今天上午!微乐富足和靠谱吗(辅... 今天上午!微乐富足和靠谱吗(辅助挂)果然真的有挂(带你开挂辅助安装)-哔哩哔哩1、完成微乐富足和靠谱...
经调查!拱趴大菠萝辅助工具(辅... 经调查!拱趴大菠萝辅助工具(辅助挂)果然是有挂(带你开挂辅助插件)-哔哩哔哩暗藏猫腻,小编详细说明拱...
随着!先锋脚本辅助(辅助挂)果... 随着!先锋脚本辅助(辅助挂)果然真的是有挂(传授开挂辅助软件)-哔哩哔哩先锋脚本辅助软件透明挂微扑克...