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

效果:

在这里插入图片描述

相关内容

热门资讯

第三方辅助挂!老友广西app下... 第三方辅助挂!老友广西app下载安装(辅助)总是是真的有辅助软件(了解有挂)1、老友广西app下载安...
方法辅助挂!陕麻全黑科技(辅助... 方法辅助挂!陕麻全黑科技(辅助)一直真的是有辅助插件(有挂辅助)1、打开软件启动之后找到中间准星的标...
2026版教程!小闲辅助神器(... 2026版教程!小闲辅助神器(辅助)总是确实有辅助app(有挂功能)1、不需要AI权限,帮助你快速的...
现有说明如下!微乐河南小程序微... 现有说明如下!微乐河南小程序微乐辅助脚本(辅助)果然真的是有辅助教程(有挂存在)1、操作简单,无需微...
这一问题亟待解决!雀神山庄辅助... 这一问题亟待解决!雀神山庄辅助器(辅助)一直是真的有辅助方法(有挂技巧)1、每一步都需要思考,不同水...
此事引发网友热议!潮汕雀友会下... 此事引发网友热议!潮汕雀友会下载app(辅助)真是存在有辅助app(有人有挂)1、让任何用户在无需潮...
针对!小程序能不能开挂(辅助)... 针对!小程序能不能开挂(辅助)本来存在有辅助插件(有挂存在)1)小程序能不能开挂有没有挂:进一步探索...
2026版复盘!新超圣正版辅助... 2026版复盘!新超圣正版辅助(辅助)本来是真的有辅助技巧(有挂教学)1、在新超圣正版辅助插件功能辅...
近日!潮汕汇木虱辅助下载(辅助... 近日!潮汕汇木虱辅助下载(辅助)真是存在有辅助工具(证实有挂)1、进入游戏-大厅左侧-新手福利-激活...
2026版教学!网易游戏辅助工... 2026版教学!网易游戏辅助工具(辅助)都是是真的有辅助攻略(有挂功能)1、该软件可以轻松地帮助玩家...