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

效果:

在这里插入图片描述

相关内容

热门资讯

有挂透视!hhpoker哪个俱... 有挂透视!hhpoker哪个俱乐部靠谱!每日必备辅助软件(有挂规律)-哔哩哔哩1)hhpoker哪个...
不少玩家反映!wepoker线... 不少玩家反映!wepoker线上大神(透视)一直是真的辅助辅助器(有挂规律)-哔哩哔哩;1、用户打开...
总结透视!wepoker怎么设... 总结透视!wepoker怎么设置房间!记者爆料辅助软件(有挂神器)-哔哩哔哩wepoker怎么设置房...
透视插件!wepoker脚本(... 透视插件!wepoker脚本(透视)都是存在有辅助软件(真实有挂)-哔哩哔哩1、下载好wepoker...
了解透视!wepoker轻量版... 您好,wepoker轻量版有透视吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...
近期!大菠萝手游辅助(透视)确... 您好,大菠萝手游辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
辅助透视!德普之星的辅助工具介... 辅助透视!德普之星的辅助工具介绍!重大消息辅助工具(有挂详情)-哔哩哔哩德普之星的辅助工具介绍破解侠...
随着!wepoker辅助器官方... 随着!wepoker辅助器官方(透视)切实是有辅助安装(有挂分析)-哔哩哔哩;1、用户打开应用后不用...
必备透视!wepoker辅助软... 必备透视!wepoker辅助软件视频!热点推荐辅助器(真的有挂)-哔哩哔哩1、必备透视!wepoke...
透视辅助!wepoker插件辅... 透视辅助!wepoker插件辅助(透视)总是有辅助插件(有挂方法)-哔哩哔哩1、wepoker插件辅...