Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <Page.Resources>
  2. <!--Use a collection view source for content that presents a list of
  3. items that can be grouped or sorted.-->
  4. //Cvs recebera via code behind uma lista de objetos do tipo IOrderedEnumerable
  5. <CollectionViewSource x:Key="Cvs" x:Name="Cvs" IsSourceGrouped="True" />
  6. </Page.Resources>
  7.  
  8. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  9. <ListView Background="White" Foreground="Black" SelectionMode="None"
  10. ItemsSource="{Binding Source={StaticResource Cvs}}">
  11. <ListView.ItemTemplate>
  12. <DataTemplate>
  13. <Grid Height="56">
  14.  
  15. <Grid.ColumnDefinitions>
  16. <ColumnDefinition Width="56"/>
  17. <ColumnDefinition Width="Auto"/>
  18. </Grid.ColumnDefinitions>
  19.  
  20. <Ellipse Grid.Column="0"
  21. Margin="4"
  22. Fill="LightGray"/>
  23.  
  24. <TextBlock Grid.Column="0"
  25. Text="{Binding Path=ShortName}"
  26. HorizontalAlignment="Center"
  27. VerticalAlignment="Center"
  28. FontSize="20"/>
  29.  
  30. <TextBlock Grid.Column="1"
  31. Text="{Binding Path=FullName}"
  32. VerticalAlignment="Center"
  33. FontSize="16"/>
  34.  
  35. </Grid>
  36. </DataTemplate>
  37. </ListView.ItemTemplate>
  38. <ListView.GroupStyle>
  39. <GroupStyle>
  40. <GroupStyle.HeaderTemplate>
  41. <DataTemplate>
  42. <Grid>
  43. <TextBlock Text="{Binding Path=Key}"
  44. Foreground="Black" Margin="20"/>
  45. </Grid>
  46. </DataTemplate>
  47. </GroupStyle.HeaderTemplate>
  48. </GroupStyle>
  49. </ListView.GroupStyle>
  50. </ListView>
  51. </Grid>
  52.  
  53. public class Contact
  54. {
  55. public string FirstName { get; set; }
  56. public string LastName { get; set; }
  57. public string FullName
  58. {
  59. get { return FirstName + " " + LastName; }
  60. }
  61. public string ShortName
  62. {
  63. get { return FirstName[0] + LastName[0].ToString(); }
  64. }
  65.  
  66. public string Inicial
  67. {
  68. get { return FirstName[0].ToString(); }
  69. }
  70. }
  71.  
  72. public MainPage()
  73. {
  74. this.InitializeComponent();
  75.  
  76. var contactList = new List<Contact>
  77. {
  78. new Contact {FirstName = "Abravanel", LastName = "Santos"},
  79. new Contact {FirstName = "Barbosa", LastName = "Sousa"},
  80. new Contact {FirstName = "Bruna", LastName = "Maria"},
  81. new Contact {FirstName = "Bruna", LastName = "Lombardi"},
  82. new Contact {FirstName = "Carlos", LastName = "Alberto"}
  83.  
  84. };
  85.  
  86. var grupo = from act in contactList.OrderBy(c => c.FirstName).ThenBy(c => c.LastName)
  87. group act by act.Inicial
  88. into grp
  89. orderby grp.Key
  90. select grp;
  91.  
  92. Cvs.Source = grupo;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement