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

效果:

在这里插入图片描述

相关内容

热门资讯

攻略教程!开挂!hhpkoer... 攻略教程!开挂!hhpkoer辅助挂是真的吗,广东雀神智能插件安装免费(我来教大家开挂辅助平台);最...
解密教程辅助!微信小程序微乐辅... 解密教程辅助!微信小程序微乐辅助器教程,芒果辅助器(透视插件开挂辅助脚本)《详细加薇13670430...
透明挂教程!开挂!情怀游戏字牌... 您好:这款情怀游戏字牌辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款情怀游戏字牌辅助游戏中打牌都...
攻略教程!辅助!hhpoker... 攻略教程!辅助!hhpoker的辅助是真的吗,超凡辅助下载(重大推荐开挂辅助安装);无需打开直接搜索...
揭秘教程辅助!小程序牵手跑得辅... 大家好,今天小编来为大家解答九游破解辅助插件官网这个问题咨询软件客服可以免费测试直接加微信(1367...
透明教程开挂!皮皮胡子辅助,随... 透明教程开挂!皮皮胡子辅助,随意玩辅助(重大推荐开挂辅助插件);致您一封信;亲爱皮皮胡子辅助玩家:《...
揭秘教程开挂!wepoker俱... 大家好,今天小编来为大家解答wepoker俱乐部开挂这个问题咨询软件客服可以免费测试直接加微信(13...
力荐教程开挂!微乐卡五星祈福有... 微信小程序雀神辅助器是一款专注玩家量身打造的游戏记牌类型软件,在微信小程序雀神辅助器这款游戏中我们可...
存在挂教程辅助!边锋辅助,新西... 大家好,今天小编来为大家解答边锋辅助这个问题咨询软件客服可以免费测试直接加微信(136704302)...
曝光教程开挂!茶馆游戏辅助,皇... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...