I am referring to the example here : http://dotnet.dzone.com/articles/using-longlistselector-control
Here is my code :
public class Chapters
{
private string mainTitle;
public string MainTitle
{
get { return mainTitle; }
set { mainTitle = value; }
}
private List<string> subTitle;
public List<string> SubTitle
{
get { return subTitle; }
set { subTitle = value; }
}
}
private static IEnumerable<HighwayCode> GetCityList()
{
return myList;
// Which already contains data:
MainTitle : Chapters
subtitle : ABC
subtitle : X
MainTitle : Chapters Two
subtitle : ASDF
subtitle : GHIJK
}
public class GroupingLayer<TKey, TElement> : IGrouping<TKey, TElement>
{
private readonly IGrouping<TKey, TElement> grouping;
public GroupingLayer(IGrouping<TKey, TElement> unit)
{
grouping = unit;
}
public TKey Key
{
get { return grouping.Key; }
}
public IEnumerator<TElement> GetEnumerator()
{
return grouping.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return grouping.GetEnumerator();
}
}
XAML:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="GroupHeader">
<Border Background="{StaticResource PhoneAccentBrush}" Margin="{StaticResource PhoneTouchTargetOverhang}" Padding="{StaticResource PhoneTouchTargetOverhang}">
<TextBlock Text="{Binding Key}"/>
</Border>
</DataTemplate>
<DataTemplate x:Key="ItemTmpl">
<Grid>
<TextBlock Style="{StaticResource PhoneTextLargeStyle}"
Foreground="Black"
Text="{Binding SubTitle}"></TextBlock>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<phone:LongListSelector x:Name="longListSelector"
IsGroupingEnabled="True" LayoutMode="List" HideEmptyGroups="False"
ItemTemplate="{StaticResource ItemTmpl}"
GroupHeaderTemplate="{StaticResource GroupHeader}"/>
and i am setting it like this :
var selected = (from c in myList
group c by c.MainTitle into n
select new GroupingLayer<string, MyObject>(n)).ToList();
longListSelector.ItemsSource = selected;
But for me its only displaying the Main Title but Sub titles are not displaying at all.
What is wrong here ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…