如何为CollectionView创建固定标头?

时间:2018-03-27 17:35:17

标签: c# wpf xaml

在我的应用程序中,我将所有customers分组为CollectionView。这工作得很好,但我找不到任何选项来修复分组项目的标题,让用户向下滚动并继续查看标题。一个简单的图形示例:

|HEADER|
Item1
Item2
Item3

用户向下滚动:

Item2
Item3

我甚至想要显示标题:

|HEADER|
Item2
Item3

XAML

xaml结构非常简单,我在ListBox中声明了CollectionViewWindow.Resources

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <Window.Resources>
       <CollectionViewSource Source="{Binding Customers}" x:Key="customerView">
           <CollectionViewSource.GroupDescriptions>
               <PropertyGroupDescription PropertyName="Country" />
           </CollectionViewSource.GroupDescriptions>
       </CollectionViewSource>
   </Window.Resources>
   <ListBox ItemSource="{Binding Source={StaticResource customerView}}" />

代码背后

public class CustomerView
{
   public CustomerView()
   {
      DataContext = new CustomerViewModel();
   }

   public class CustomerViewModel 
   {  
       public List<Customer> Customers { get; set; }

       //Fill the available customers
       public CustomerViewModel()
       {
           List<Customer> customers = GetCustomers();
       }
   }
}

这是一个非常简单的例子。我想这些代码并不是必需的,只是为了更好地解释这种情况。

当用户向下滚动时,如何使标题保持可见?

感谢您的支持。

0 个答案:

没有答案