Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: WinUI SelectorBar and SelectorBarItem #16480

Merged
merged 14 commits into from
May 23, 2024
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
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/ItemExclusions.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Page Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />
<Compile Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />
<None Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />
<Page Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />
<Compile Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />
<None Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />

<Page Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\WebView2Tests\**" />
<Compile Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\WebView2Tests\**" />
Expand All @@ -54,5 +57,9 @@
<Page Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />
<Compile Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />
<None Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\**" />

<Page Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />
<Compile Remove="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />
<None Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SelectorBarTests\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<local:TestPage
x:Class="MUXControlsTestApp.SelectorBarPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MUXControlsTestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="40">
<Grid RowDefinitions="Auto, Auto" ColumnDefinitions="Auto, *">
<TextBlock Text="SelectorBar OutputDebugString Levels:" VerticalAlignment="Center" Margin="2"/>
<ComboBox x:Name="cmbSelectorBarOutputDebugStringLevel" Margin="2" MinWidth="100" HorizontalAlignment="Stretch" SelectedIndex="0" Grid.Column="1" SelectionChanged="CmbSelectorBarOutputDebugStringLevel_SelectionChanged">
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Info</ComboBoxItem>
<ComboBoxItem>Verbose</ComboBoxItem>
</ComboBox>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2">
<CheckBox x:Name="chkSelectorBar" Content="SelectorBar" IsChecked="True" Margin="2"/>
<CheckBox x:Name="chkItemsView" Content="ItemsView" IsChecked="True" Margin="2"/>
<CheckBox x:Name="chkItemsRepeater" Content="ItemsRepeater" IsChecked="True" Margin="2"/>
<CheckBox x:Name="chkItemContainer" Content="ItemContainer" Margin="2"/>
</StackPanel>
</Grid>
<Button x:Name="navigateToSummary" AutomationProperties.Name="navigateToSummary" Margin="2" HorizontalAlignment="Stretch">SelectorBar in summary page</Button>
<Button x:Name="navigateToSample" AutomationProperties.Name="navigateToSample" Margin="2" HorizontalAlignment="Stretch">SelectorBar in sample page</Button>
</StackPanel>
</local:TestPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Common;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Private.Controls;

//using WEX.TestExecution;
//using WEX.TestExecution.Markup;
//using WEX.Logging.Interop;
using Uno.UI.Samples.Controls;

namespace MUXControlsTestApp
{
[Sample("SelectorBar")]
public sealed partial class SelectorBarPage : TestPage
{
public SelectorBarPage()
{
LogController.InitializeLogging();
this.InitializeComponent();

navigateToSummary.Click += delegate { Frame.NavigateWithoutAnimation(typeof(SelectorBarSummaryPage), 0); };
navigateToSample.Click += delegate { Frame.NavigateWithoutAnimation(typeof(SelectorBarSamplePage), 0); };
}

private void CmbSelectorBarOutputDebugStringLevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//if (chkSelectorBar != null && chkSelectorBar.IsChecked == true)
//{
// MUXControlsTestHooks.SetOutputDebugStringLevelForType(
// "SelectorBar",
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2,
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2);
//}

//if (chkItemsView != null && chkItemsView.IsChecked == true)
//{
// MUXControlsTestHooks.SetOutputDebugStringLevelForType(
// "ItemsView",
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2,
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2);
//}

//if (chkItemContainer != null && chkItemContainer.IsChecked == true)
//{
// MUXControlsTestHooks.SetOutputDebugStringLevelForType(
// "ItemContainer",
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2,
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2);
//}

//if (chkItemsRepeater != null && chkItemsRepeater.IsChecked == true)
//{
// MUXControlsTestHooks.SetOutputDebugStringLevelForType(
// "ItemsRepeater",
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2,
// cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2);
//}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<local:TestPage
x:Class="MUXControlsTestApp.SelectorBarSamplePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MUXControlsTestApp"
xmlns:dataModel="using:MUXControlsTestApp.Samples.Model"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RowDefinitions="Auto, Auto, Auto" ColumnDefinitions="Auto">
<SelectorBar x:Name="selectorBar" AutomationProperties.Name="selectorBar" Margin="2" SelectionChanged="SelectorBar_SelectionChanged">
<SelectorBarItem x:Name="selectorBarItemDeleted" Text="Deleted" Icon="Delete" IsEnabled="False"/>
<SelectorBarItem x:Name="selectorBarItemCut1" Text="Cut1" Icon="Cut" Visibility="Collapsed"/>
<SelectorBarItem x:Name="selectorBarItemRemote" Text="Remote" Icon="Remote" AutomationProperties.Name="Remote Photos"/>
<SelectorBarItem x:Name="selectorBarItemShared" Text="Shared" Icon="Share"/>
<SelectorBarItem x:Name="selectorBarItemCut2" Text="Cut2" Icon="Cut" Visibility="Collapsed"/>
<SelectorBarItem x:Name="selectorBarItemFavorites" Text="Favorites" Icon="Favorite" IsSelected="True"/>
</SelectorBar>

<ItemsView x:Name="photos" AutomationProperties.Name="photos" Margin="2" Width="500" Height="500" Grid.Row="1">
<ItemsView.ItemTransitionProvider>
<LinedFlowLayoutItemCollectionTransitionProvider/>
</ItemsView.ItemTransitionProvider>
<ItemsView.Layout>
<LinedFlowLayout LineHeight="96" ItemsStretch="Fill" MinItemSpacing="4" LineSpacing="4"/>
</ItemsView.Layout>
<ItemsView.ItemTemplate>
<DataTemplate x:DataType="dataModel:Recipe">
<ItemContainer MinWidth="72" Height="96" Background="Gray">
<Image Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image.Source>
<BitmapImage DecodePixelHeight="96" UriSource="{Binding ImageUri}"/>
</Image.Source>
</Image>
</ItemContainer>
</DataTemplate>
</ItemsView.ItemTemplate>
</ItemsView>

<StackPanel Orientation="Horizontal" Margin="2" Grid.Row="2">
<TextBlock Text="Selected SelectorBarItem:" Margin="2"/>
<TextBlock x:Name="tblSelectedSelectorBarItem" Margin="2"/>
</StackPanel>
</Grid>
</local:TestPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.UI.Xaml.Controls;
using MUXControlsTestApp.Samples.Model;
using System;
using System.Collections.ObjectModel;
using Uno.UI.Samples.Controls;

namespace MUXControlsTestApp
{
[Sample("SelectorBar")]
public sealed partial class SelectorBarSamplePage : TestPage
{
private ObservableCollection<Recipe> _colRemotePhotos = null;
private ObservableCollection<Recipe> _colSharedPhotos = null;
private ObservableCollection<Recipe> _colFavoritePhotos = null;

public SelectorBarSamplePage()
{
this.InitializeComponent();

_colRemotePhotos = new ObservableCollection<Recipe>();
_colSharedPhotos = new ObservableCollection<Recipe>();
_colFavoritePhotos = new ObservableCollection<Recipe>();

int imageCount = 20;

for (int itemIndex = 0; itemIndex < imageCount; itemIndex++)
{
_colRemotePhotos.Add(new Recipe()
{
ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + 1))
});
_colSharedPhotos.Add(new Recipe()
{
ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + imageCount + 1))
});
_colFavoritePhotos.Add(new Recipe()
{
ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + 2 * imageCount + 1))
});
}
}

~SelectorBarSamplePage()
{
}

private void SelectorBar_SelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args)
{
if (sender.SelectedItem == selectorBarItemRemote)
{
photos.ItemsSource = _colRemotePhotos;
}
else if (sender.SelectedItem == selectorBarItemShared)
{
photos.ItemsSource = _colSharedPhotos;
}
else
{
photos.ItemsSource = _colFavoritePhotos;
}

if (tblSelectedSelectorBarItem != null)
{
tblSelectedSelectorBarItem.Text = sender.SelectedItem == null ? "null" : sender.SelectedItem.Name;
}
}
}
}
Loading
Loading