我试图在数十年内对名字进行分组。几十年的专栏是通过转换器创建的:
<sdk:DataGridTemplateColumn Header="Decades" Width="Auto" >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Kennitala, Converter={StaticResource AgeToDecadeConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
代码behinde看起来像这样:
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
int yearBorn = System.Convert.ToInt16("19" + value.ToString().Substring(4, 2));
int yearNow = DateTime.Now.Year;
string decade = (yearNow - yearBorn).ToString().Substring(0, 1) + "0";
return decade;
}
问题在于所有名称都属于同一组,就像它在十年数字中看不到差异一样,而我可以将直接来自数据库的列分组