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)微乐小程序游戏破解器...
技术分享开挂!微信小程序微乐辅... 技术分享开挂!微信小程序微乐辅助器,微乐贵阳捉鸡麻将能不能开挂-一贯是真的有辅助工具在进入微信小程序...
科技介绍开挂!微乐小程序家乡自... 科技介绍开挂!微乐小程序家乡自建房辅助app,微乐自建房脚本如何下载-其实是有辅助神器1、超多福利:...
重大通报辅助!微信小程序微乐辅... 重大通报辅助!微信小程序微乐辅助器教程,微乐小程序微乐家乡辅助器-都是真的有辅助插件重大通报辅助!微...
玩家必备教程辅助!微信小程序游... 玩家必备教程辅助!微信小程序游戏破解微乐游戏,微信小程序微乐安徽辅助苹果-确实有辅助脚本1、完成微信...
科技分享开挂!微乐手游辅助脚本... 科技分享开挂!微乐手游辅助脚本平台,微乐小程序辅助器免费-其实有辅助神器一、微乐手游辅助脚本平台可以...
发现玩家辅助!微乐小程序辅助工... 您好,微乐小程序辅助工具这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多...
推荐一款透视挂!微乐小程序家乡... 推荐一款透视挂!微乐小程序家乡自建房辅助app,微乐河南小程序微乐辅助脚本-原来存在有辅助挂微乐小程...
一起来探讨开挂!微乐小程序开挂... 一起来探讨开挂!微乐小程序开挂黑科技,微乐自建房免费黑科技推荐-本来真的是有辅助脚本小薇(辅助器软件...
2024教程辅助!微信小程序微... 2024教程辅助!微信小程序微乐辅助免费,微乐小程序辅助教程-都是是真的有辅助挂1、点击下载安装,微...