Skip to content
Merged
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
Binary file added WinUIGallery/Assets/ControlImages/LayoutPanel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WinUIGallery/Assets/ControlImages/WrapPanel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions WinUIGallery/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WinUIGallery"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:WinUIGallery.Models"
xmlns:pages="using:WinUIGallery.Pages"
Title="MainWindow"
mc:Ignorable="d">
Expand Down Expand Up @@ -144,6 +145,35 @@
IsTabStop="False"
Loaded="OnNavigationViewControlLoaded"
SelectionChanged="OnNavigationViewSelectionChanged">
<NavigationView.Resources>
<DataTemplate x:Key="NavigationItemContentTemplate" x:DataType="models:ControlInfoDataItem">
<Grid
HorizontalAlignment="Stretch"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
VerticalAlignment="Center"
Text="{x:Bind Title}"
TextTrimming="CharacterEllipsis" />
<Border
Grid.Column="1"
Padding="6,2"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
Background="{ThemeResource SystemFillColorCautionBackgroundBrush}"
CornerRadius="4"
Visibility="{x:Bind IsExperimental}">
<TextBlock
Foreground="{ThemeResource SystemFillColorCautionBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Experimental" />
</Border>
</Grid>
</DataTemplate>
</NavigationView.Resources>
<Frame
x:Name="rootFrame"
Navigated="OnRootFrameNavigated"
Expand Down
16 changes: 13 additions & 3 deletions WinUIGallery/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public void EnsureNavigationSelection(string id)

public void AddNavigationMenuItems()
{
DataTemplate navigationItemContentTemplate = (DataTemplate)NavigationViewControl.Resources["NavigationItemContentTemplate"];

foreach (var group in ControlInfoDataSource.Instance.Groups.OrderBy(i => i.Title).Where(i => !i.IsSpecialSection))
{
var itemGroup = new NavigationViewItem() { Content = group.Title, Tag = group.UniqueId, DataContext = group, Icon = GetIcon(group.IconGlyph) };
Expand All @@ -258,14 +260,22 @@ public void AddNavigationMenuItems()

foreach (var item in group.Items)
{
var itemInGroup = new NavigationViewItem() { IsEnabled = item.IncludedInBuild, Content = item.Title, Tag = item.UniqueId, DataContext = item };
var itemInGroup = new NavigationViewItem()
{
IsEnabled = item.IncludedInBuild,
Content = item,
ContentTemplate = navigationItemContentTemplate,
DataContext = item,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Tag = item.UniqueId,
};

var itemInGroupMenuFlyoutItem = new MenuFlyoutItem() { Text = $"Copy Link to {item.Title} sample", Icon = new FontIcon() { Glyph = "\uE8C8" }, Tag = item };
itemInGroupMenuFlyoutItem.Click += this.OnMenuFlyoutItemClick;
itemInGroup.ContextFlyout = new MenuFlyout() { Items = { itemInGroupMenuFlyoutItem } };

itemGroup.MenuItems.Add(itemInGroup);
AutomationProperties.SetName(itemInGroup, item.Title);
AutomationProperties.SetName(itemInGroup, item.IsExperimental ? $"{item.Title}, Experimental" : item.Title);
AutomationProperties.SetAutomationId(itemInGroup, item.UniqueId);
}

Expand Down Expand Up @@ -529,7 +539,7 @@ public bool EnsureItemIsVisibleInNavigation(string name)
{
foreach (NavigationViewItem child in item.MenuItems)
{
if ((string)child.Content == name)
if (child.DataContext is ControlInfoDataItem childData && childData.Title == name)
{
// We are the item corresponding to the selected one, update selection!

Expand Down
91 changes: 90 additions & 1 deletion WinUIGallery/SampleSupport/Data/ControlInfoData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,33 @@
"ItemsRepeater"
]
},
{
"UniqueId": "PagerControl",
"Tags": [
"pagination",
"pages",
"navigation"
],
"Title": "PagerControl",
"BaseClasses": [
"Object",
"DependencyObject",
"UIElement",
"FrameworkElement",
"Control"
],
"ApiNamespace": "Microsoft.UI.Xaml.Controls",
"Subtitle": "A control that lets users navigate through a numbered collection of pages.",
"ImagePath": "ms-appx:///Assets/ControlImages/PagerControl.png",
"Description": "PagerControl provides numbered page navigation with multiple display modes and configurable navigation buttons.",
"SourcePath": "/PagerControl",
"IsExperimental": true,
"RelatedControls": [
"PipsPager",
"ItemsRepeater",
"ListView"
]
},
{
"UniqueId": "ScrollView",
"Tags": [
Expand Down Expand Up @@ -2550,7 +2577,40 @@
"RelativePanel"
]
},

{
"UniqueId": "LayoutPanel",
"Tags": [
"layout panel",
"custom layout",
"non virtualizing layout",
"panel"
],
"Title": "LayoutPanel",
"BaseClasses": [
"Object",
"DependencyObject",
"UIElement",
"FrameworkElement",
"Panel"
],
"ApiNamespace": "Microsoft.UI.Xaml.Controls",
"Subtitle": "A panel that uses a Layout object to measure and arrange its children.",
"ImagePath": "ms-appx:///Assets/ControlImages/LayoutPanel.png",
"Description": "Use LayoutPanel to apply a reusable Layout, including a custom NonVirtualizingLayout, to ordinary panel children. LayoutPanel also provides border, corner radius, and padding properties.",
"SourcePath": "/LayoutPanel",
"IsExperimental": true,
"Docs": [
{
"Title": "LayoutPanel - API",
"Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.layoutpanel"
}
],
"RelatedControls": [
"Panel",
"StackLayout",
"ItemsRepeater"
]
},
{
"UniqueId": "RelativePanel",
"Tags": [
Expand Down Expand Up @@ -2699,6 +2759,35 @@
"RelativePanel"
]
},
{
"UniqueId": "WrapPanel",
"Tags": [
"wrap",
"responsive layout",
"flow layout",
"spacing"
],
"Title": "WrapPanel",
"BaseClasses": [
"Object",
"DependencyObject",
"UIElement",
"FrameworkElement",
"Panel"
],
"ApiNamespace": "Microsoft.UI.Xaml.Controls",
"Subtitle": "A layout panel that arranges child elements in rows or columns and automatically wraps them onto new lines.",
"ImagePath": "ms-appx:///Assets/ControlImages/WrapPanel.png",
"Description": "Use a WrapPanel to arrange child elements sequentially and move overflowing items to a new row or column. You can configure its orientation, spacing, padding, and whether the final item stretches to fill the remaining space.",
"SourcePath": "/WrapPanel",
"IsExperimental": true,
"RelatedControls": [
"StackPanel",
"VariableSizedWrapGrid",
"ItemsRepeater",
"GridView"
]
},
{
"UniqueId": "Viewbox",
"Tags": [
Expand Down
29 changes: 29 additions & 0 deletions WinUIGallery/Samples/ItemsRepeater/FlowLayoutVirtualization.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- header
Use FlowLayout with ItemsRepeater to wrap and virtualize a large collection.
--- xaml
<ScrollViewer Width="520" Height="320"
HorizontalScrollMode="Disabled"
VerticalScrollMode="Enabled">
<ItemsRepeater ItemsSource="{x:Bind FlowLayoutItems}"
ItemTemplate="{StaticResource FlowItemTemplate}">
<ItemsRepeater.Layout>
<FlowLayout
Orientation="$(Orientation)"
LineAlignment="$(LineAlignment)"
MinItemSpacing="$(MinItemSpacing)"
LineSpacing="$(LineSpacing)"/>
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollViewer>

<DataTemplate x:Key="FlowItemTemplate" x:DataType="local:FlowLayoutItem">
<Border Width="96" Height="64">
<TextBlock Text="{x:Bind Label}"/>
</Border>
</DataTemplate>
--- c#
public IReadOnlyList<FlowLayoutItem> FlowLayoutItems { get; } = Enumerable.Range(1, 500)
.Select(index => new FlowLayoutItem($"Item {index}"))
.ToList();

public sealed record FlowLayoutItem(string Label);
118 changes: 118 additions & 0 deletions WinUIGallery/Samples/ItemsRepeater/ItemsRepeaterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="FlowItemTemplate" x:DataType="local:FlowLayoutItem">
<Border
Width="96"
Height="64"
Background="{ThemeResource ControlFillColorDefaultBrush}"
BorderBrush="{ThemeResource ControlStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="{StaticResource ControlCornerRadius}">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{x:Bind Label}" />
</Border>
</DataTemplate>

<StackLayout
x:Name="VerticalStackLayout"
Orientation="Vertical"
Expand Down Expand Up @@ -278,6 +293,109 @@
</controls:ControlExample.Substitutions>
</controls:ControlExample>

<controls:ControlExample
HeaderText="Virtualize a wrapping collection with FlowLayout"
IsExperimental="True"
SampleDefinition="ItemsRepeater\FlowLayoutVirtualization.txt">
<StackPanel Spacing="8">
<TextBlock
Text="Scroll through 500 items. ItemsRepeater creates and recycles only the elements needed near the viewport."
TextWrapping="Wrap" />
<ScrollViewer
x:Name="FlowScrollViewer"
Width="520"
Height="320"
HorizontalAlignment="Left"
HorizontalScrollBarVisibility="Disabled"
HorizontalScrollMode="Disabled"
IsHorizontalScrollChainingEnabled="False"
IsVerticalScrollChainingEnabled="False"
VerticalScrollBarVisibility="Auto"
VerticalScrollMode="Enabled">
<ItemsRepeater
x:Name="FlowRepeater"
ElementClearing="FlowRepeater_ElementClearing"
ElementPrepared="FlowRepeater_ElementPrepared"
HorizontalCacheLength="0"
ItemTemplate="{StaticResource FlowItemTemplate}"
ItemsSource="{x:Bind FlowLayoutItems}"
VerticalCacheLength="0">
<ItemsRepeater.Layout>
<FlowLayout
x:Name="FlowLayout1"
LineAlignment="Start"
LineSpacing="8"
MinItemSpacing="8" />
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollViewer>
<TextBlock
x:Name="RealizedCountText"
AutomationProperties.LiveSetting="Polite"
Text="Realized elements: 0 of 500" />
</StackPanel>

<controls:ControlExample.Options>
<StackPanel Spacing="12">
<RadioButtons
AutomationProperties.AutomationId="FlowLayoutOrientation"
AutomationProperties.Name="FlowLayout orientation"
Header="Orientation"
SelectionChanged="OrientationButtons_SelectionChanged">
<RadioButton
AutomationProperties.AutomationId="FlowLayoutHorizontal"
AutomationProperties.Name="Horizontal flow"
Content="Horizontal"
IsChecked="True"
Tag="Horizontal" />
<RadioButton
AutomationProperties.AutomationId="FlowLayoutVertical"
AutomationProperties.Name="Vertical flow"
Content="Vertical"
Tag="Vertical" />
</RadioButtons>
<ComboBox
AutomationProperties.AutomationId="FlowLayoutLineAlignment"
AutomationProperties.Name="Line alignment"
Header="LineAlignment"
SelectedIndex="0"
SelectionChanged="LineAlignmentComboBox_SelectionChanged">
<ComboBoxItem Content="Start" Tag="Start" />
<ComboBoxItem Content="Center" Tag="Center" />
<ComboBoxItem Content="Space between" Tag="SpaceBetween" />
<ComboBoxItem Content="Space evenly" Tag="SpaceEvenly" />
</ComboBox>
<Slider
AutomationProperties.AutomationId="FlowLayoutItemSpacing"
AutomationProperties.Name="Minimum item spacing"
Header="MinItemSpacing"
Maximum="32"
SnapsTo="Ticks"
StepFrequency="2"
TickFrequency="2"
Value="8"
ValueChanged="ItemSpacingSlider_ValueChanged" />
<Slider
AutomationProperties.AutomationId="FlowLayoutLineSpacing"
AutomationProperties.Name="Line spacing"
Header="LineSpacing"
Maximum="32"
SnapsTo="Ticks"
StepFrequency="2"
TickFrequency="2"
Value="8"
ValueChanged="LineSpacingSlider_ValueChanged" />
</StackPanel>
</controls:ControlExample.Options>

<controls:ControlExample.Substitutions>
<controls:ControlExampleSubstitution Key="Orientation" Value="{x:Bind FlowLayout1.Orientation, Mode=OneWay}" />
<controls:ControlExampleSubstitution Key="LineAlignment" Value="{x:Bind FlowLayout1.LineAlignment, Mode=OneWay}" />
<controls:ControlExampleSubstitution Key="MinItemSpacing" Value="{x:Bind FlowLayout1.MinItemSpacing, Mode=OneWay}" />
<controls:ControlExampleSubstitution Key="LineSpacing" Value="{x:Bind FlowLayout1.LineSpacing, Mode=OneWay}" />
</controls:ControlExample.Substitutions>
</controls:ControlExample>

<controls:ControlExample
SampleDefinition="ItemsRepeater\ItemsrepeaterMixedTypeCollection.txt">
<StackPanel>
Expand Down
Loading