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
13 changes: 2 additions & 11 deletions AIDevGallery/Controls/SampleContainer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,14 @@
Visibility="Visible" />
<Button
x:Name="SampleDebugInfoButton"
AutomationProperties.Name="Performance details"
Visibility="Collapsed"
Style="{StaticResource SubtleButtonStyle}">
<TextBlock
x:Name="SampleDebugInfoButtonText"
AutomationProperties.AccessibilityView="Raw"
FontSize="12"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
<Button.Flyout>
<Flyout>
<TextBlock
x:Name="SampleDebugInfoContent"
MaxWidth="300"
FontFamily="Consolas"
FontSize="14"
LineHeight="20"
TextWrapping="WrapWholeWords" />
</Flyout>
</Button.Flyout>
</Button>
<ContentPresenter x:Name="FooterContentPresenter" Content="{x:Bind FooterContent, Mode=OneWay}" />
</WrapPanel>
Expand Down
7 changes: 5 additions & 2 deletions AIDevGallery/Controls/SampleContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,15 @@ public void ShowDebugInfo(string? contents)
SampleDebugInfoButtonText.Visibility = Visibility.Collapsed;
SampleDebugInfoButton.Visibility = Visibility.Collapsed;
SampleDebugInfoButtonText.Text = string.Empty;
SampleDebugInfoContent.Text = string.Empty;
ToolTipService.SetToolTip(SampleDebugInfoButton, null);
Microsoft.UI.Xaml.Automation.AutomationProperties.SetFullDescription(SampleDebugInfoButton, string.Empty);
return;
}

SampleDebugInfoButtonText.Text = contents.Split('\n')[0];
SampleDebugInfoContent.Text = contents;

ToolTipService.SetToolTip(SampleDebugInfoButton, contents);
Microsoft.UI.Xaml.Automation.AutomationProperties.SetFullDescription(SampleDebugInfoButton, contents);

SampleDebugInfoButtonText.Visibility = Visibility.Visible;
SampleDebugInfoButton.Visibility = Visibility.Visible;
Expand Down
25 changes: 25 additions & 0 deletions AIDevGallery/Helpers/NavigationViewItemHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,6 +12,28 @@ namespace AIDevGallery.Helpers;

internal static class NavigationViewItemHelper
{
public static void AppendControlTypeToName(this NavigationViewItem item, string label)
{
RoutedEventHandler? loadedHandler = null;
loadedHandler = (sender, _) =>
{
if (sender is not NavigationViewItem navItem)
{
return;
}

var peer = FrameworkElementAutomationPeer.FromElement(navItem) ?? FrameworkElementAutomationPeer.CreatePeerForElement(navItem);
var controlType = peer?.GetLocalizedControlType();
if (!string.IsNullOrWhiteSpace(controlType))
{
AutomationProperties.SetName(navItem, $"{label}, {controlType}");
navItem.Loaded -= loadedHandler;
}
};

item.Loaded += loadedHandler;
}

public static IEnumerable<NavigationViewItem> Flatten(this IEnumerable<NavigationViewItem> source)
{
foreach (var item in source)
Expand Down
2 changes: 2 additions & 0 deletions AIDevGallery/Pages/APIs/APIOverview.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@
<TextBlock
Margin="2,0,0,0"
FontSize="18"
AutomationProperties.HeadingLevel="Level1"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="Explore Windows AI APIs" />

<ItemsView
x:Name="APIViewer"
AutomationProperties.Name="Explore Windows AI APIs"
IsItemInvokedEnabled="True"
ItemInvoked="APIViewer_ItemInvoked"
ItemsSource="{x:Bind wcrAPIs, Mode=OneWay}"
Expand Down
2 changes: 2 additions & 0 deletions AIDevGallery/Pages/APIs/APISelectionPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using AIDevGallery.Helpers;
using AIDevGallery.Models;
using AIDevGallery.Samples;
using AIDevGallery.Telemetry.Events;
Expand Down Expand Up @@ -79,6 +80,7 @@ private void SetupAPIs()
if (existingItem == null)
{
existingItem = new NavigationViewItem() { Content = CreateWrappedText(apiDefinition.Category), Icon = new FontIcon() { Glyph = "\uF0E2" }, SelectsOnInvoked = false, IsExpanded = true };
existingItem.AppendControlTypeToName(apiDefinition.Category);
NavView.MenuItems.Add(existingItem);
}

Expand Down
3 changes: 3 additions & 0 deletions AIDevGallery/Pages/Scenarios/ScenarioOverviewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
x:Name="CategoryHeader"
Margin="2,0,0,0"
FontSize="16"
FontWeight="SemiBold"
AutomationProperties.HeadingLevel="Level1"
Text="{x:Bind Name}"
TextWrapping="Wrap" />
<!--<TextBlock
Expand All @@ -89,6 +91,7 @@
TextWrapping="Wrap" />-->
<ItemsView
Grid.Row="2"
AutomationProperties.Name="{x:Bind Name}"
IsItemInvokedEnabled="True"
ItemInvoked="ScenarioItemsView_ItemInvoked"
ItemsSource="{x:Bind Scenarios}"
Expand Down
1 change: 1 addition & 0 deletions AIDevGallery/Pages/Scenarios/ScenarioSelectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private void SetUpScenarios(string? filter = null)
foreach (var scenarioCategory in ScenarioCategoryHelpers.AllScenarioCategories)
{
var categoryMenu = new NavigationViewItem() { Content = scenarioCategory.Name, Icon = new FontIcon() { Glyph = scenarioCategory.Icon }, Tag = scenarioCategory };
categoryMenu.AppendControlTypeToName(scenarioCategory.Name);
ToolTip categoryToolTip = new() { Content = scenarioCategory.Name };
ToolTipService.SetToolTip(categoryMenu, categoryToolTip);

Expand Down
18 changes: 15 additions & 3 deletions AIDevGallery/Samples/SharedCode/Controls/SemanticComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,23 @@ private async void SuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxT
{
// Since selecting an item will also change the text,
// only listen to changes caused by user entering text.
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput)
{
var searchResults = await Search(sender.Text);
sender.ItemsSource = searchResults.Select(item => item["Text"]);
return;
}

string query = sender.Text;
var searchResults = await Search(query);

if (sender.Text != query)
{
return;
}

var suggestions = searchResults.Select(item => item["Text"]).ToList();
sender.ItemsSource = suggestions;

NarratorHelper.Announce(sender, $"{suggestions.Count} result{(suggestions.Count == 1 ? string.Empty : "s")}", "SemanticComboBoxSuggestionsActivityId"); // <exclude-line>
}

private static void OnEmbeddingGeneratorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down
Loading