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

效果:

在这里插入图片描述

相关内容

热门资讯

玩家交流!精品乐清麻将辅助脚本... 玩家交流!精品乐清麻将辅助脚本软件工具,精品乐清麻将从前有辅助解密APP(有挂讲解);1、很好的精品...
黑科技教程!嵊州越乡游麻将开挂... 黑科技教程!嵊州越乡游麻将开挂脚本软件工具,嵊州越乡游麻将真是真的有开挂揭幕APP(真的有挂);嵊州...
总算清楚!!逸趣吉安透视挂脚本... 总算清楚!!逸趣吉安透视挂脚本软件工具,逸趣吉安切实有透视挂详情APP(有挂头条)是一款可以让一直输...
玩家必看教程!!苍南麻将透视脚... 玩家必看教程!!苍南麻将透视脚本软件工具,苍南麻将原本真的有透视详情APP(有挂技术);详细苍南麻将...
必知教程!乐友开挂脚本软件工具... 必知教程!乐友开挂脚本软件工具,乐友一向真的有开挂必备APP(有挂技巧)是一款可以让一直输的玩家,快...
一分钟教你!众胜麻将开挂脚本软... 一分钟教你!众胜麻将开挂脚本软件工具,众胜麻将素来是有开挂了解APP(有挂详情);众胜麻将软件透视开...
一分钟带你了解!土豆互娱辅助挂... 一分钟带你了解!土豆互娱辅助挂脚本软件工具,土豆互娱起初有辅助挂曝光APP(有挂技巧);1、这是跨平...
必备科技!来一盘河南麻将开挂脚... 必备科技!来一盘河南麻将开挂脚本软件工具,来一盘河南麻将果然是真的有开挂解迷APP(确实有挂);来一...
玩家亲测!川渝互娱辅助挂脚本软... 玩家亲测!川渝互娱辅助挂脚本软件工具,川渝互娱最初有辅助挂了解APP(有挂辅助),川渝互娱是用手机号...
一分钟揭秘!决胜奕福辅助脚本软... 一分钟揭秘!决胜奕福辅助脚本软件工具,决胜奕福原本真的有辅助教你APP(有挂神器);1、决胜奕福ai...