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... 总算了解开挂脚本!wepoker辅助功能开透视工具,总是存在有挂(了解有挂)wepoker透视方法中...
一分钟秒懂透视挂技巧!AAPo... 一分钟秒懂透视挂技巧!AAPoKer辅助功能开透视工具,真是真的有挂(有挂透视)1)AAPoKer免...
技术分享透视挂攻略!智星菠萝德... 技术分享透视挂攻略!智星菠萝德州辅助功能开透视工具,果然有挂(有挂方略)1、超多福利:超高返利,海量...
总算了解透视挂教程!AAPoK... 总算了解透视挂教程!AAPoKer辅助功能开透视工具,都是真的有挂(证实有挂)运AAPoKer辅助工...
新手必备开挂教程!aapoke... 新手必备开挂教程!aapoker辅助功能开透视工具,真是存在有挂(有挂解惑)1、首先打开aapoke...
最新技巧透视挂脚本!微扑克辅助... 最新技巧透视挂脚本!微扑克辅助功能开透视工具,其实是有挂(有挂猫腻)1、金币登录送、破产送、升级送、...
盘点几款透视挂工具!AAPoK... 盘点几款透视挂工具!AAPoKer辅助功能开透视工具,原来有挂(有挂技巧)1、首先打开AAPoKer...
今日焦点开挂方法!德扑圈辅助功... 今日焦点开挂方法!德扑圈辅助功能开透视工具,总是是真的有挂(有挂辅助)该软件可以轻松地帮助玩家将德扑...
发现玩家辅助软件!智星德州扑克... 发现玩家辅助软件!智星德州扑克辅助功能开透视工具,切实存在有挂(真的有挂)1、超多福利:超高返利,海...
交流学习经验开挂工具!WPK辅... 交流学习经验开挂工具!WPK辅助功能开透视工具,一直真的是有挂(有挂辅助)WPK透视方法中分为三种模...