A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
The VirtualizingWrapPanel supports horizontal and vertical orientation, caching, container recycling and grouping [[Derive from VirtualizingWrapPanel][1]] , so I made a sample of grouping the Buttons in VirtualizingItemsControl as below:
XAML code:
<vwp:VirtualizingItemsControl Name="vic"
VirtualizingPanel.CacheLengthUnit="Item"
VirtualizingPanel.ScrollUnit="Pixel"
VirtualizingPanel.VirtualizationMode="Recycling"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<vwp:VirtualizingWrapPanel Orientation="Vertical" SpacingMode="None" StretchItems="False" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.GroupStyle>
<GroupStyle HidesIfEmpty="True">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock HorizontalAlignment="Left"
FontWeight="Bold"
FontSize="14"
Text="Width:" />
<TextBlock HorizontalAlignment="Left"
FontWeight="Bold"
FontSize="14"
Text="{Binding Name}" />
</WrapPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ItemsControl.GroupStyle>
</vwp:VirtualizingItemsControl>
C# code:
public MainWindow()
{
InitializeComponent();
List<Button> buttons = new List<Button>();
for(int i=1;i<100;i++)
{
Button button = new Button();
if(i<50)
{
button = new Button() { Content = "Button" + i.ToString(), Width = 90, Height = 40 };
}else
{
button = new Button() { Content = "Button" + i.ToString(), Width = 120, Height = 40 };
}
buttons.Add(button);
}
vic.ItemsSource = buttons;
ICollectionView cv = CollectionViewSource.GetDefaultView(vic.ItemsSource);
cv.GroupDescriptions.Add(new PropertyGroupDescription("Width"));
}
The result picture is:
Did my answer give you any help? If it didn't, please let me know and give me more details.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.