I need Regions list on my UI.Here key is the Region. How bind the key on xaml(UI) as listview.
MainViewModel
- public ObservableCollection<WorkItem>ItemDetails { get; set; }
- public class WorkItem
- {
- public string country { get; set; }
- public string capital { get; set; }
- public string Region { get; set; }
- public string S_region { get; set; }
- public double? Area { get; set; }
- public int Population { get; set; }
- }
this is the linq query that i wrote to group items by Region Property.
- var queryRegion = from s in ItemDetails
- group s by s.Region into newGroup
- orderby newGroup.Key
- select newGroup;
MainPage.xaml
- <Grid>
- <TextBlock Text="Regions: " Foreground="White" FontSize="20" Margin="10,20,0,0" FontWeight="Bold"/>
-
- <ListView Background="White" Margin="10,70,0,0" FontSize="60"
- FontWeight="Bold"
- Foreground="Black" ItemsSource="{Binding queryRegion}"
- VerticalAlignment="Stretch"
- HorizontalAlignment="Stretch"
- IsItemClickEnabled="True"
- ItemClick="ListView_ItemClick">
-
- <ListView.ItemContainerStyle >
- <Style TargetType="ListViewItem" >
- <Setter Property="FontSize"
- Value="20" />
- <Setter Property="BorderBrush" Value="LightGray" />
- <Setter Property="BorderThickness" Value="0,0,0,01"/>
- <Setter Property="Margin" Value="10,0,0,0"/>
-
- </Style>
- </ListView.ItemContainerStyle>
- <ListView.ItemTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding queryRegion.Key}" Foreground="Black"/>
- </DataTemplate>
- </ListView.ItemTemplate>
-
- </ListView>
-
- </Grid>