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

效果:

在这里插入图片描述

相关内容

热门资讯

透视手筋!agpoker辅助(... 透视手筋!agpoker辅助(WPK下载)确实真的是有辅助攻略(哔哩哔哩)1)agpoker辅助辅助...
总结了解!都莱大菠萝怎么设置(... 总结了解!都莱大菠萝怎么设置(辅助)战地一贯有挂辅助安装(哔哩哔哩)1、起透看视 都莱大菠萝怎么设置...
透视教学!aapoker怎么设... 透视教学!aapoker怎么设置提高好牌几率(透视)微乐小程序免费黑科技在线下载(果然存在有辅助软件...
网友热议!拱趴大菠萝怎么开挂(... 网友热议!拱趴大菠萝怎么开挂(透视)福建大菠萝辅助透视(辅助)本来真的是有教程(哔哩哔哩)1、上手简...
透视妙招!hhpoker辅助靠... 您好,hhpoker辅助靠谱吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
普及了解!盛世2私人辅助(辅助... 普及了解!盛世2私人辅助(辅助)天天爱河池麻将都是存在有辅助脚本(哔哩哔哩)1、玩家可以在盛世2私人...
此事备受玩家关注!德普之星透视... 此事备受玩家关注!德普之星透视辅助插件(透视)如何下载微乐自建房黑科技入口(总是是有辅助教程)-哔哩...
透视攻略!newpoker怎么... 透视攻略!newpoker怎么安装脚本(透视)雀神挂件脚本(辅助)总是真的是有插件(哔哩哔哩);1、...
透视妙招!德州透视插件(HHp... 透视妙招!德州透视插件(HHpoker机器人)本来有辅助方法(哔哩哔哩)德州透视插件辅助器是一种具有...
专业了解!朋朋政和辅助(辅助)... 专业了解!朋朋政和辅助(辅助)天天保定麻将切实存在有辅助脚本(哔哩哔哩)1、玩家可以在朋朋政和辅助透...