I wanted to Develop a similar layout like Longlist Selector Wp8 in Windows phone 8.1.
I came across a issue, my list is not appearing.
XAML page
<Grid >
<Grid.Resources>
<CollectionViewSource x:Name="MainGrps"
IsSourceGrouped="True"/>
</Grid.Resources>
<ListView ItemsSource="{Binding Source={StaticResource MainGrps}}" Margin="50">
<ListView.ItemTemplate>
<DataTemplate >
<Grid Background="Gray">
<StackPanel>
<TextBlock Foreground="White" FontSize="20" Text="{Binding ItmName}"/>
<TextBlock Foreground="White" FontSize="20" Text="{Binding ItmType}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="True" >
<GroupStyle.HeaderTemplate>
<DataTemplate >
<Grid Background="Red">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding GrpItmName}" Foreground="White"/>
<TextBlock Text="{Binding ItemsCount}" Foreground="White"/>
</StackPanel>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
Code Behind:
private void OnPageLoaded(object sender, RoutedEventArgs e)
{
lst_grp = new List<Grp>();
for (int i = 0; i < 10; i++)
{
Grp grp = new Grp();
grp.GrpItmName = "grp name " + i;
grp.ItemsCount = i;
grp.LstItms = new List<Itm>();
Itm itm = new Itm();
itm.ItmName = "itm name " + i;
itm.ItmType = "itm type " + i;
grp.LstItms.Add(itm);
grp.LstItms.Add(itm);
grp.LstItms.Add(itm);
lst_grp.Add(grp);
}
this.MainGrps.Source = lst_grp;
}
Is there any problem with above code?
Please help me to figure it out or suggest if you have working code.
Try to add this in the XAML inside the ListView tag:
Or try to set the width and the height parameter of the ListView manually.. Just to try..
Let me know!
Change
to: