Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions samples/WinUI.TableView.SampleApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
<NavigationViewItem Content="Custom Sorting" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<NavigationViewItem Content="Grouping">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xF168;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Filtering">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE71C;" />
Expand Down
1 change: 1 addition & 0 deletions samples/WinUI.TableView.SampleApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private void OnNavigationSelectionChanged(NavigationView sender, NavigationViewS
"Editing" => typeof(EditingPage),
"Sorting" => typeof(SortingPage),
"Custom Sorting" => typeof(CustomizeSortingPage),
"Grouping" => typeof(GroupingPage),
"Data Export" => typeof(ExportPage),
"Large Dataset" => typeof(LargeDataPage),
"Conditional Cell Styling" => typeof(ConditionalStylingPage),
Expand Down
76 changes: 76 additions & 0 deletions samples/WinUI.TableView.SampleApp/Pages/GroupingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<Page x:Class="WinUI.TableView.SampleApp.Pages.GroupingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUI.TableView.SampleApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tv="using:WinUI.TableView"
xmlns:controls="using:WinUI.TableView.SampleApp.Controls"
d:DataContext="{d:DesignInstance Type=local:ExampleViewModel}"
mc:Ignorable="d">

<Grid>
<controls:SamplePresenter Header="Row Grouping"
Description="Group rows by a data field using the GroupByPath property. Users can expand and collapse groups, and control group header visibility and item counts.">
<controls:SamplePresenter.Example>
<tv:TableView ItemsSource="{Binding Items}"
GroupByPath="{x:Bind GroupByPath, Mode=OneWay}"
ShowGroupHeaders="{Binding IsOn, ElementName=showGroupHeaders, Mode=TwoWay}"
ShowGroupItemCount="{Binding IsOn, ElementName=showItemCount, Mode=TwoWay}"
GroupSortDirection="{x:Bind GroupSortDirection, Mode=OneWay}" />
</controls:SamplePresenter.Example>
<controls:SamplePresenter.Options>
<StackPanel VerticalAlignment="Top"
Spacing="12">
<ComboBox x:Name="groupByComboBox"
Header="Group By"
Width="200"
SelectedIndex="0"
SelectionChanged="OnGroupBySelectionChanged">
<ComboBoxItem Content="Department" Tag="Department" />
<ComboBoxItem Content="Gender" Tag="Gender" />
<ComboBoxItem Content="Designation" Tag="Designation" />
<ComboBoxItem Content="(None)" Tag="" />
</ComboBox>
<ComboBox x:Name="sortDirectionComboBox"
Header="Group Sort Direction"
Width="200"
SelectedIndex="0"
SelectionChanged="OnSortDirectionChanged">
<ComboBoxItem Content="Ascending" />
<ComboBoxItem Content="Descending" />
</ComboBox>
<ToggleSwitch x:Name="showGroupHeaders"
IsOn="True"
Header="Show Group Headers"
OnContent="True"
OffContent="False" />
<ToggleSwitch x:Name="showItemCount"
IsOn="True"
Header="Show Item Count"
OnContent="True"
OffContent="False" />
</StackPanel>
</controls:SamplePresenter.Options>
<controls:SamplePresenter.Xaml>
<x:String xml:space="preserve">
&lt;tv:TableView ItemsSource="{Binding Items}"
GroupByPath="$(GroupByPath)"
ShowGroupHeaders="$(ShowGroupHeaders)"
ShowGroupItemCount="$(ShowGroupItemCount)"
GroupSortDirection="$(GroupSortDirection)">
</x:String>
</controls:SamplePresenter.Xaml>
<controls:SamplePresenter.Substitutions>
<controls:CodeSubstitution Key="GroupByPath"
Value="{x:Bind GroupByPath, Mode=OneWay}" />
<controls:CodeSubstitution Key="ShowGroupHeaders"
Value="{x:Bind showGroupHeaders.IsOn, Mode=OneWay}" />
<controls:CodeSubstitution Key="ShowGroupItemCount"
Value="{x:Bind showItemCount.IsOn, Mode=OneWay}" />
<controls:CodeSubstitution Key="GroupSortDirection"
Value="{x:Bind GroupSortDirection, Mode=OneWay}" />
</controls:SamplePresenter.Substitutions>
</controls:SamplePresenter>
</Grid>
</Page>
54 changes: 54 additions & 0 deletions samples/WinUI.TableView.SampleApp/Pages/GroupingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.UI.Xaml.Controls;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WinUI.TableView.SampleApp.Pages;

public sealed partial class GroupingPage : Page, INotifyPropertyChanged
{
private string? _groupByPath = "Department";
private SortDirection _groupSortDirection = SortDirection.Ascending;

public GroupingPage()
{
InitializeComponent();
}

public string? GroupByPath
{
get => _groupByPath;
set { _groupByPath = value; OnPropertyChanged(); }
}

public SortDirection GroupSortDirection
{
get => _groupSortDirection;
set { _groupSortDirection = value; OnPropertyChanged(); }
}

private void OnGroupBySelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ComboBox comboBox && comboBox.SelectedItem is ComboBoxItem item)
{
var path = item.Tag?.ToString();
GroupByPath = string.IsNullOrEmpty(path) ? null : path;
}
}

private void OnSortDirectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ComboBox comboBox)
{
GroupSortDirection = comboBox.SelectedIndex == 0
? SortDirection.Ascending
: SortDirection.Descending;
}
}

public event PropertyChangedEventHandler? PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Loading
Loading