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.9分钟了解!爱玩联盟辅助软... 1.9分钟了解!爱玩联盟辅助软件,pokerworld辅助器,方案教程(有挂细节)-哔哩哔哩1、很好...
推荐透视!wepoker可以透... 推荐透视!wepoker可以透视码,hhpoker怎么开透视,学习教程(有挂实锤)-哔哩哔哩1、全新...
曝光透视!fishpoker透... 曝光透视!fishpoker透视底牌!真是有辅助工具(有挂攻略)-哔哩哔哩1、下载好fishpoke...
重大通报!!丽水茶苑脚本,we... 重大通报!!丽水茶苑脚本,wepoker透视功能下载,方式教程(有挂详情)-哔哩哔哩暗藏猫腻,小编详...
有挂透视!智星德州辅助译码插件... 有挂透视!智星德州辅助译码插件靠谱吗!切实是有辅助攻略(有挂工具)-哔哩哔哩1、全新机制【智星德州辅...
开挂透视!德州透视脚本,小程序... 开挂透视!德州透视脚本,小程序微乐辅助器免费版,烘培教程(有挂教程)-哔哩哔哩运德州透视脚本辅助工具...
有挂透视!aapoker ai... 有挂透视!aapoker ai插件,德扑圈透视,妙计教程(有挂规律)-哔哩哔哩1、游戏颠覆性的策略玩...
解密关于!心悦踢坑神器软件下载... 解密关于!心悦踢坑神器软件下载,wepoker俱乐部辅助,大纲教程(今日头条)-哔哩哔哩1、用户打开...
关于透视!wpk透视是真的假的... 关于透视!wpk透视是真的假的,哈糖大菠萝开挂,举措教程(有挂方法)-哔哩哔哩暗藏猫腻,小编详细说明...
关于透视!哈糖大菠萝挂法!真是... 关于透视!哈糖大菠萝挂法!真是存在有辅助工具(有挂解惑)-哔哩哔哩1、下载好哈糖大菠萝挂法正确养号方...