我目前正在开发基于Silverlight2的考勤记录。我想为学生和班级创建一个随时间出勤的可视化,但我很难想出一个好的方法。我想象的那种东西是一个网格,学生在垂直轴上,日期沿水平方向,在学生和日期交叉处的符号表示是否存在。理想情况下,用于生成可视化的方法也可用于生成打印材料,但这不是必需的。 (Silverlight没有内置的打印支持,所以它必须是SQL Server Reporting Services或类似的。)
这是Excel中我需要显示的数据类型的简单模型:
(显然有很棒的Silverlight样式)
以下是我目前关于如何解决这个问题的想法:
......x...oo.ox...x....
等字符串来执行此类操作,然后以固定宽度字体显示。这个解决方案让我的眼睛流血,因为它似乎是对绿屏终端时代的回归,特别是当Silverlight是基于矢量的时候。基本上每一道思路都会引导我编写自己的全功能Silverlight /报告引擎,这超出了我想要做的范围。另外,我真的不想让未来的维护者留下一些可怕的定制黑客显示器和放大器。报告系统。 (我不想结束TheDailyWTF!)
这就是Silverlight的可视化形式 - 我无法决定在哪里指导我的工作。
答案 0 :(得分:4)
我只能想到一个简单的两级ItemsControl(ListBox)解决方案。内部视觉元素可以是一个看起来像'O'或'X'的Styled CheckBox,这里是我刚刚为你制作的样本。当然,您需要在顶部与复选框对齐的DateHeader集合。
alt text http://img339.imageshack.us/img339/8695/grid.jpg
XAML
<UserControl.Resources>
<DataTemplate x:Key="CellTemplate">
<Grid Width="25" Height="25">
<CheckBox IsChecked="{Binding IsPresent}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="RowTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="4,0,0,0" Text="{Binding Name}" TextWrapping="Wrap"/>
<ItemsControl ItemsSource="{Binding WorkingDays}" HorizontalAlignment="Left" VerticalAlignment="Top" ItemTemplate="{StaticResource CellTemplate}" Grid.Column="1" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</DataTemplate>
</UserControl.Resources>
<ItemsControl x:Name="lstWorkingDaysMain" ItemsSource="{Binding}" ItemTemplate="{StaticResource RowTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
C#
public class Student
{
public Student()
{
WorkingDays = new List<WorkingDay>();
}
public string Name { get; set; }
public List<WorkingDay> WorkingDays { get; set; }
}
public class WorkingDay
{
public bool IsPresent{get; set;}
public DateTime Date { get; set; }
}
测试数据填充在xaml.cs后面的代码中
List<Student> students = new List<Student>();
Student student = new Student() { Name = "Aaaaaa" };
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,5), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,6), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,7), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,8), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,9), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,10), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,11), IsPresent=true} );
student.WorkingDays.Add(new WorkingDay() { Date=new DateTime(2009,5,12), IsPresent=true} );
students.Add(student);
student = new Student() { Name = "Bbbbbb" };
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 5), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 6), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 7), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 8), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 9), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 10), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 11), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 12), IsPresent = true });
students.Add(student);
student = new Student() { Name = "Cccccc" };
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 5), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 6), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 7), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 8), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 9), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 10), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 11), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 12), IsPresent = false });
students.Add(student);
student = new Student() { Name = "Dddddd" };
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 5), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 6), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 7), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 8), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 9), IsPresent = false });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 10), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 11), IsPresent = true });
student.WorkingDays.Add(new WorkingDay() { Date = new DateTime(2009, 5, 12), IsPresent = true });
students.Add(student);
this.DataContext = students;