I'm trying display ListView grouping. I did as below:
ListView.xaml. cs
ListViewModel lvm = new ListViewModel();
lvUsers3.ItemsSource = lvm.getData();
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers3.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Type");
view.GroupDescriptions.Add(groupDescription);
ListView. xaml
<ListView Name="lvUsers3" Margin="0,197,94,0" ItemsSource="{Binding tvq}">
<ListView.View>
<GridView>
<GridViewColumn Header="FirstName" Width="100" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Header="LastName" Width="100" DisplayMemberBinding="{Binding LastName}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" FontSize="14" FontStyle="Normal" Text="{Binding Type}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
ListViewModel. cs
namespace LayoutMVVM.ViewModels
{
public class ListViewModel
{
public List<test_view> getData()
{
testViewClassDataContext tv = new testViewClassDataContext();
List<test_view> tvq = (from tt in tv.test_views
select tt).ToList();
return tvq;
}
}
}
On result I see that is grouped but the "type" value is missing (like was hidden?)
When you have applied the grouping you have created a group object that contains your sub items and this is what you are binding your group header to
the group object doesn't contain a Type property to bind to
try "{Binding Name}"
instead of "{Binding Type}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.