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)微扑克全自动机器人(软件透明挂)一直真的有挂(2021已更新)(哔哩哔哩)...
终于知道!!微扑克辅助软件(透... 终于知道!!微扑克辅助软件(透明黑科技)AA德州教程(2026已更新)(哔哩哔哩)1、不需要AI权限...
黑科技规律(微扑克wpk真的有... 黑科技规律(微扑克wpk真的有辅助吗)外挂透明挂辅助插件(透视)一直是真的有挂(有挂教学)-哔哩哔哩...
黑科技美元局(wpk德州专用辅... 黑科技美元局(wpk德州专用辅助器)外挂透明挂辅助软件(透视)原来真的有挂(有挂分享)-哔哩哔哩1、...
一分钟揭秘!!微扑克wpk辅助... 一分钟揭秘!!微扑克wpk辅助(辅助挂)攻略方法(2023已更新)(哔哩哔哩)是一款可以让一直输的玩...
辅助黑科技(WePoKe)we... 辅助黑科技(WePoKe)wepoke德扑之星(软件透明挂)切实真的是有挂(2024已更新)(哔哩哔...
黑科技真的(WePoKe)we... 黑科技真的(WePoKe)wepoke黑科技设备(透视)都是是真的有挂(2022已更新)(哔哩哔哩)...
最新研发!微扑克wpk有挂吗(... 最新研发!微扑克wpk有挂吗(透明黑科技)揭秘教程(2023已更新)(哔哩哔哩);是一款可以让一直输...
黑科技安装(德州ai软件使用)... 黑科技安装(德州ai软件使用)外挂透明挂辅助黑科技(透视)一直真的有挂(有挂实锤)-哔哩哔哩;一、德...
分享认知!wopoker真的有... 分享认知!wopoker真的有挂吗(ai代打)技巧教程(2022已更新)(哔哩哔哩)1、用户打开应用...