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

效果:

在这里插入图片描述

相关内容

热门资讯

透视安装!(wepoke最新)... 透视安装!(wepoke最新)外挂辅助透视!(扑克王)玩家教你(2024已更新)(哔哩哔哩);致您一...
第八分钟私人局!wepoker... 第八分钟私人局!wepoker辅助是真的假的,aapoker辅助包(透视)教你攻略(有挂方略)wep...
三分钟辅助!wpk ai辅助购... 《三分钟辅助!wpk ai辅助购买渠道(透明挂黑科技)外挂透明挂辅助智能(2024已更新)(哔哩哔哩...
黑科技脚本!德州之星app辅助... 黑科技脚本!德州之星app辅助,wepoke可以来好牌,第三方教程(有挂攻略)-哔哩哔哩;详细德州之...
科技新动态!(哈糖大菠萝)外挂... 科技新动态!(哈糖大菠萝)外挂透视透明挂辅助透视!(aapoker正规)2025新版技巧(2026已...
第4分钟知晓!poker wo... 第4分钟知晓!poker world辅助,WePOker有没有透视方法(透视)切实教程(有挂教学)1...
两分钟理解!aapoker俱乐... 两分钟理解!aapoker俱乐部后台可以操作吗(透明挂黑科技)外挂透明挂辅助ai(2026已更新)(...
大神推荐!wpk ai辅助购买... 大神推荐!wpk ai辅助购买渠道,wepower可以设置德州,透明挂教程(有挂技巧)-哔哩哔哩;人...
揭秘真相!(wpk专用)外挂辅... 【福星临门,好运相随】;揭秘真相!(wpk专用)外挂辅助插件!(aapker代理)解说技巧(2025...
两分钟领会!智星菠萝辅助怎么买... 两分钟领会!智星菠萝辅助怎么买,拱趴大菠萝万能挂(透视)力荐教程(存在有挂)1、用户打开应用后不用登...