Silverlight的DataGrid合并单元格
程序员文章站
2022-04-08 14:50:59
现在也不知道还有没有同学做Silverlight开发了,我是一个Silverlight菜鸟,遇到问题也很难百度查到。就简单的记录一下这两天遇到的问题,并做了一个简单的小Demo,希望能够帮助到其他同学,并为自己翻看。 DataGrid合并单元格,实现结果如下: Silverlight后台代码如下: ......
现在也不知道还有没有同学做Silverlight开发了,我是一个Silverlight菜鸟,遇到问题也很难百度查到。就简单的记录一下这两天遇到的问题,并做了一个简单的小Demo,希望能够帮助到其他同学,并为自己翻看。
DataGrid合并单元格,实现结果如下:
Silverlight后台代码如下:
/// <summary> /// 学生实体类 /// </summary> public class Students { private string name; /// <summary> /// 学生姓名 /// </summary> public string Name { get { return name; } set { name = value; } } private int age; /// <summary> /// 学生年龄 /// </summary> public int Age { get { return age; } set { age = value; } } private string sex; /// <summary> /// 学生性别 /// </summary> public string Sex { get { return sex; } set { sex = value; } } private List<Courses> coursesLists = new List<Courses>(); /// <summary> /// 课程列表 /// </summary> public List<Courses> CoursesLists { get { return coursesLists; } set { coursesLists = value; } } }
/// <summary> /// 课程实体类 /// </summary> public class Courses { private double score; /// <summary> /// 课程分数 /// </summary> public double Score { get { return score; } set { score = value; } } private string course; /// <summary> /// 课程名称 /// </summary> public string Course { get { return course; } set { course = value; } } }
/// <summary> /// 张山的课程列表 /// </summary> /// <returns></returns> private static List<Courses> ZhangSan() { List<Courses> zhangsan = new List<Courses>(); Courses shuxue = new Courses(); shuxue.Course = "数学"; shuxue.Score = 88; zhangsan.Add(shuxue); Courses yingyu = new Courses(); yingyu.Course = "英语"; yingyu.Score = 89; zhangsan.Add(yingyu); Courses yuwen = new Courses(); yuwen.Course = "语文"; yuwen.Score = 87; zhangsan.Add(yuwen); Courses dili = new Courses(); dili.Course = "地理"; dili.Score = 86; zhangsan.Add(dili); return zhangsan; } /// <summary> /// 李氏的课程列表 /// </summary> /// <returns></returns> private static List<Courses> LiSi() { List<Courses> lisi = new List<Courses>(); Courses shuxue = new Courses(); shuxue.Course = "数学"; shuxue.Score = 90; lisi.Add(shuxue); Courses yingyu = new Courses(); yingyu.Course = "英语"; yingyu.Score = 95; lisi.Add(yingyu); Courses yuwen = new Courses(); yuwen.Course = "语文"; yuwen.Score = 98; lisi.Add(yuwen); Courses dili = new Courses(); dili.Course = "地理"; dili.Score = 97; lisi.Add(dili); return lisi; } /// <summary> /// 王武的课程列表 /// </summary> /// <returns></returns> private static List<Courses> WangWu() { List<Courses> wangwu = new List<Courses>(); Courses shuxue = new Courses(); shuxue.Course = "数学"; shuxue.Score = 77; wangwu.Add(shuxue); Courses yingyu = new Courses(); yingyu.Course = "英语"; yingyu.Score = 78; wangwu.Add(yingyu); Courses yuwen = new Courses(); yuwen.Course = "语文"; yuwen.Score = 79; wangwu.Add(yuwen); return wangwu; } /// <summary> /// 赵刘的课程列表 /// </summary> /// <returns></returns> private static List<Courses> ZhaoLiu() { List<Courses> zhaoliu = new List<Courses>(); Courses shuxue = new Courses(); shuxue.Course = "数学"; shuxue.Score = 90; zhaoliu.Add(shuxue); Courses yingyu = new Courses(); yingyu.Course = "英语"; yingyu.Score = 95; zhaoliu.Add(yingyu); Courses yuwen = new Courses(); yuwen.Course = "语文"; yuwen.Score = 98; zhaoliu.Add(yuwen); return zhaoliu; }
/// <summary> /// 得到学生列表数据 /// </summary> /// <returns></returns> public static List<Students> GetStudentLists() { List<Students> studentLists = new List<Students>(); studentLists.Add(new Students() { Name = "张山", Age = 20, Sex = "男", CoursesLists = ZhangSan() }); studentLists.Add(new Students() { Name = "李氏", Age = 25, Sex = "女", CoursesLists = LiSi() }); studentLists.Add(new Students() { Name = "王武", Age = 35, Sex = "男", CoursesLists = WangWu() }); studentLists.Add(new Students() { Name = "赵刘", Age = 30, Sex = "女", CoursesLists = ZhaoLiu() }); return studentLists; } /// <summary> /// Silverlight页面初始化 /// </summary> public DataGridMergeRows() { InitializeComponent(); dataGrid.ItemsSource = GetStudentLists(); }
以下是Silverlight UI页面代码
<sdk:DataGrid x:Name="dataGrid" HorizontalAlignment="Center" AutoGenerateColumns="False" Height="470" Margin="10,0,0,0" VerticalAlignment="Top" Width="911"> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn Header="姓名" Binding="{Binding Name}" IsReadOnly="True" Width="108"/> <sdk:DataGridTextColumn Header="性别" Binding="{Binding Sex}" IsReadOnly="True" Width="108"/> <sdk:DataGridTextColumn Header="年龄" Binding="{Binding Age}" IsReadOnly="True" Width="108"/> <sdk:DataGridTemplateColumn Header="课程" IsReadOnly="True" Width="108" > <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding Path=CoursesLists}"> <ItemsControl.ItemTemplate> <DataTemplate> <Border MinHeight="25" BorderThickness="0,0,0,1" Margin="0,0,0,-1" BorderBrush="#FFC9CACA"> <TextBlock Text="{Binding Path=Course}" VerticalAlignment="Center" Margin="5" HorizontalAlignment="Left" TextWrapping="NoWrap"/> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> <sdk:DataGridTemplateColumn Header="成绩" IsReadOnly="True" Width="108" > <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding Path=CoursesLists}"> <ItemsControl.ItemTemplate> <DataTemplate> <Border MinHeight="25" BorderThickness="0,0,0,1" Margin="0,0,0,-1" BorderBrush="#FFC9CACA"> <TextBlock Text="{Binding Path=Score}" VerticalAlignment="Center" Margin="5" HorizontalAlignment="Left" TextWrapping="NoWrap"/> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> </sdk:DataGrid.Columns> </sdk:DataGrid>
上一篇: Java的内存机制
推荐阅读
-
jquery 合并内容相同的单元格(示例代码)_jquery
-
C#实现改变DataGrid某一行和单元格颜色的方法
-
基于Silverlight DataGrid中无代码设置开始与结束日期DatePicker的实现方法
-
用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
-
基于Silverlight DataGrid中无代码设置开始与结束日期DatePicker的实现方法
-
C#实现改变DataGrid某一行和单元格颜色的方法
-
用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
-
JSP中动态合并单元格的实例代码
-
jquery 合并内容相同的单元格(示例代码)
-
axure中的单元格怎么合并?