Reputation: 1901
I want to hide the group header in LongListSelector
if the number of items in the list is small (like the list of apps in WP, if apps is less than 30).
LongListSelector.ItemsSource = myList;
if (myList.Count < 10)
{
//hide group header
}
Is this possible?
UPDATE
So, I try:
LongListSelector.ItemsSource = myList;
if (myList.Count < 10)
{
LongListSelector.GroupHeaderTemplate = null;
}
And it works, but I still wait more beautiful advices. Thanks! :)
EDIT
My LongListSelector:
<phone:LongListSelector
Name="UsersListGroup"
IsGroupingEnabled="True"
LayoutMode="List"
HideEmptyGroups="False"
ItemTemplate="{StaticResource usersItemTemplate}"
GroupHeaderTemplate="{StaticResource groupHeaderTemplate}"
JumpListStyle="{StaticResource LongListSelectorJumpListStyle}"
Margin="1,36,-1,10"
VirtualizingStackPanel.VirtualizationMode="Recycling"/>
Templates:
<DataTemplate x:Key="usersItemTemplate">
<Grid x:Name="FriendsPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Name="FriendPanel" Orientation="Horizontal" Margin="0,0,0,17" Tag="{Binding Id}" Tap="FriendPanel_Tap" >
<Image Height="75"
Width="75"
HorizontalAlignment="Left"
Margin="6,0,9,0"
Name="Avatar"
Stretch="Fill"
VerticalAlignment="Top"
Source="{Binding Avatar, StringFormat=http://myurl.com/\{0\}}"/>
<TextBlock Text="offline"
TextWrapping="Wrap"
Margin="-75,78,0,0"
Style="{StaticResource PhoneTextSmallStyle}" >
<i:Interaction.Triggers>
<ec:DataTrigger Binding="{Binding IsOnline}" Value="1">
<ec:ChangePropertyAction PropertyName="Text" Value="online"/>
</ec:DataTrigger>
</i:Interaction.Triggers>
</TextBlock>
<StackPanel >
<TextBlock
Text="{Binding Name}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}">
</TextBlock>
<TextBlock Text="{Binding Aboutself}"
TextWrapping="Wrap"
Margin="12,-6,12,0"
Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
<Style x:Key="LongListSelectorJumpListStyle" TargetType="phone:LongListSelector">
<Setter Property="GridCellSize" Value="113,113"/>
<Setter Property="LayoutMode" Value="Grid" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="Purple"
Width="113" Height="113" Margin="6" >
<TextBlock Text="{Binding Title}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
FontSize="48" Padding="6"
Foreground="White"
VerticalAlignment="Center"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Cs:
private static ObservableCollection<Group<T>> GetItemGroups<T>(IEnumerable<T> itemList, Func<T, string> getKeyFunc)
{
IEnumerable<Group<T>> groupList = from item in itemList
group item by getKeyFunc(item) into g
orderby g.Key
select new Group<T>(Convert.ToString(g.Key.ToLower()[0]), g);
var groupObservable = new ObservableCollection<Group<T>>(groupList);
return groupObservable;
}
private ObservableCollection<Group<GYUser>> GetUserGroups(ObservableCollection<GYUser> collectionFriends)
{
return GetItemGroups(collectionFriends, c => Convert.ToString(c.Name.ToLower()[0]));
}
Friends = GetUserGroups(new ObservableCollection<GYUser>(response.Result.Friends));
UsersListGroup.ItemsSource = Friends;
Upvotes: 2
Views: 854
Reputation: 2994
Are you using the LongListSelector that comes inbuilt in WP8? If so, try setting IsGroupingEnabled to false.
If you are using the WP7 version that comes in your controls, try defining two data templates in your page resources, one of which has a grid with width and height 0 and swap GroupHeaderTemplate to that data template if your no of items < 10.
Upvotes: 2