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)运辅助工具,进...
今日科普!微乐小程序辅助工具!... 今日科普!微乐小程序辅助工具!微乐小程序游戏破解器下载(真是真的有辅助器);1、有没有辅助教程、有透...
大家学习交流!微乐小程序自建房... 大家学习交流!微乐小程序自建房辅助!微乐小程序游戏破解器(都是存在有辅助脚本)1、每一步都需要思考,...
终于知道!微乐小程序自建房辅助... 终于知道!微乐小程序自建房辅助!微乐小程序自建房透视下载(确实有辅助脚本)该软件可以轻松地帮助玩家将...
一分钟教会你!微乐小程序辅助工... 一分钟教会你!微乐小程序辅助工具!微乐小程序辅助开发(都是真的是有辅助工具)1、玩家可以在线上大神俱...
玩家必备攻略!微乐小程序自建房... 玩家必备攻略!微乐小程序自建房辅助!微信小程序微乐辅助器教程(真是是真的有辅助技巧)所有人都在同一条...
技巧知识分享!微乐小程序自建房... 技巧知识分享!微乐小程序自建房辅助!微乐斗地主有挂吗(好像是有辅助攻略)1、进入到是否有挂之后,能看...
推荐攻略!微乐小程序辅助工具!... 推荐攻略!微乐小程序辅助工具!微乐自建房辅助下载(总是真的有辅助软件)1、脚本辅助下载、免费透视脚本...
总算清楚!微乐小程序自建房辅助... 总算清楚!微乐小程序自建房辅助!微信小程序多乐辅助器(原来是真的有辅助器)透视方法中分为三种模型:靠...
教程攻略!微乐小程序自建房辅助... 教程攻略!微乐小程序自建房辅助!微信微乐游戏苹果辅助器(都是真的有辅助攻略)一、游戏安装教程牌型概率...