Windows phone 7 如何在LongListSelector中隐藏组标题?
如果列表中的项目数较少(如WP中的应用程序列表,如果应用程序少于30个),我想在Windows phone 7 如何在LongListSelector中隐藏组标题?,windows-phone-7,xaml,windows-phone-8,longlistselector,Windows Phone 7,Xaml,Windows Phone 8,Longlistselector,如果列表中的项目数较少(如WP中的应用程序列表,如果应用程序少于30个),我想在LongListSelector中隐藏组标题 <DataTemplate x:Key="usersItemTemplate"> <Grid x:Name="FriendsPanel" Grid.Row="1" Margin="12,0,12,0"> <StackPanel Name="FriendPanel" Orientation="Ho
LongListSelector
中隐藏组标题
<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>
LongListSelector.ItemsSource=myList;
如果(myList.Count<10)
{
//隐藏组标题
}
这可能吗
<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>
更新
<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>
因此,我尝试:
LongListSelector.ItemsSource = myList;
if (myList.Count < 10)
{
LongListSelector.GroupHeaderTemplate = null;
}
<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>
LongListSelector.ItemsSource=myList;
如果(myList.Count<10)
{
LongListSelector.GroupHeaderTemplate=null;
}
它是有效的,但我仍然在等待更美好的建议。谢谢!:)
<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>
编辑
<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>
我的长列表选择器:
<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"/>
<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>
模板:
<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>
<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>
<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>
政务司司长:
<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>
私有静态ObservableCollection GetItemGroups(IEnumerable itemList,Func getKeyFunc)
{
IEnumerable groupList=来自itemList中的项
按getKeyFunc(项)将项分组为g
orderby g.Key
选择新组(Convert.ToString(g.Key.ToLower()[0]),g);
var groupObservable=新的ObservableCollection(groupList);
可观察的回报率;
}
私有ObservableCollection GetUserGroups(ObservableCollection collectionFriends)
{
返回GetItemGroups(collectionFriends,c=>Convert.ToString(c.Name.ToLower()[0]);
}
Friends=GetUserGroups(新的ObservableCollection(response.Result.Friends));
UsersListGroup.ItemsSource=朋友;
是否使用WP8内置的LongListSelector?如果是,请尝试将IsGroupingEnabled设置为false
<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>
<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>
如果您使用的是控件中的WP7版本,请尝试在页面资源中定义两个数据模板,其中一个具有宽度和高度为0的网格,如果项目数<10,请将GroupHeaderTemplate交换到该数据模板。谢谢您的回答。我使用WP8并尝试使用启用分组,但如果我将属性设置为false,则列表为空:(我可能需要更仔细地看一下您的代码……您能把它放在这里吗?看看……从我的头顶上,您能试着从这个语句中删除orderby并通过getKeyFunc(item)选中?IEnumerable groupList=from item-in-itemList-group-item-in-item-in-itemList-group-item)进入g orderby g.Key选择新组(Convert.ToString(g.Key.ToLower()[0]),g);我检查了它,再次得到了空列表。嘿……对我来说,最简单的方法似乎是在页面中定义一个空数据模板,并将其设置为GroupHeaderTemplate
<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>