TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Neethu pradeep
NA
36
10.6k
How to bind a key of linq into xaml listview
Dec 13 2018 2:48 AM
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>
Reply
Answers (
3
)
Single linq Statement
Complied Quries...?