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

效果:

在这里插入图片描述

相关内容

热门资讯

详细说明!wpk辅助神器,太坑... 详细说明!wpk辅助神器,太坑了原先是有挂(2025已更新)(哔哩哔哩);详细wpk辅助神器攻略(w...
黑科技线上!德扑之星实战,太坑... 黑科技线上!德扑之星实战,太坑了先前真的有挂(2020已更新)(哔哩哔哩);是一款可以让一直输的玩家...
今日公布!wpk俱乐部管理后台... 今日公布!wpk俱乐部管理后台,太坑了原来是真的有挂(2026已更新)(哔哩哔哩);是一款可以让一直...
记者揭秘!德州ai辅助神器,太... 【福星临门,好运相随】;记者揭秘!德州ai辅助神器,太坑了一向存在有挂(2023已更新)(哔哩哔哩)...
黑科技好牌!微扑克有辅助挂,太... 黑科技好牌!微扑克有辅助挂,太坑了原先是有挂(2025已更新)(哔哩哔哩);1、这是跨平台的微扑克有...
玩家必看秘籍!aapoker辅... 玩家必看秘籍!aapoker辅助,太坑了好像真的有挂(2026已更新)(哔哩哔哩);1、完成aapo...
重大通报!wpk辅助器安装,太... 重大通报!wpk辅助器安装,太坑了起初真的有挂(2026已更新)(哔哩哔哩);相信小伙伴都知道这个w...
推荐几款新版!微扑克必胜技巧,... 《推荐几款新版!微扑克必胜技巧,太坑了从来真的有挂(2024已更新)(哔哩哔哩)》 微扑克必胜技巧软...
分辨真假!微扑克俱乐部设置,太... 分辨真假!微扑克俱乐部设置,太坑了从来真的有挂(2020已更新)(哔哩哔哩);详细微扑克俱乐部设置攻...
记者揭秘!德州poker有外挂... 记者揭秘!德州poker有外挂,太坑了总是真的是有挂(2022已更新)(哔哩哔哩);德州poker有...