Skip to content

Adding accessible context menus to TabView pages #1664

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions WinUIGallery/Helpers/TabViewHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,11 @@ public static void PopulateTabViewContextMenu(MenuFlyout menuFlyout)
};
menuFlyout.Items.Add(moveRightItem);
}

// If the context menu ended up with no items at all, then we'll prevent it from being shown.
if (menuFlyout.Items.Count == 0)
{
menuFlyout.Hide();
}
}
}
17 changes: 17 additions & 0 deletions WinUIGallery/Helpers/UIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ static public void AnnounceActionForAccessibility(UIElement ue, string annouceme
peer.RaiseNotificationEvent(AutomationNotificationKind.ActionCompleted,
AutomationNotificationProcessing.ImportantMostRecent, annoucement, activityID);
}

public static T GetParent<T>(DependencyObject child) where T : DependencyObject
{
DependencyObject current = child;

while (current != null)
{
if (current is T parent)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's behavior of this function that we want (not current behavior) when current DO is of type T and it has a parent of type T?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is reasonable to return the first result, otherwise you would need to scan up to the root to find the latest T

{
return parent;
}

current = VisualTreeHelper.GetParent(current);
}

return null;
}
}
4 changes: 2 additions & 2 deletions WinUIGallery/Helpers/Win32WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace WinUIGallery.Helpers;

internal class Win32WindowHelper
{
private static WinProc newWndProc = null;
private static nint oldWndProc = nint.Zero;
private WinProc newWndProc = null;
private nint oldWndProc = nint.Zero;

private POINT? minWindowSize = null;
private POINT? maxWindowSize = null;
Expand Down
3 changes: 2 additions & 1 deletion WinUIGallery/Samples/ControlPages/TabViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
<TabViewItem
Content="{x:Bind DataContent}"
Header="{x:Bind DataHeader}"
IconSource="{x:Bind DataIconSource}" />
IconSource="{x:Bind DataIconSource}"
ContextFlyout="{x:Bind TabViewContextMenu}" />
</DataTemplate>
</TabView.TabItemTemplate>
</TabView>
Expand Down
4 changes: 2 additions & 2 deletions WinUIGallery/Samples/SamplePages/TabContentSampleControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<TextBlock Text="{Binding}" Style="{ThemeResource TitleTextBlockStyle}" />
<TextBlock Text="Drag the Tab outside of the window to spawn a new window." Style="{ThemeResource SubtitleTextBlockStyle}" />
<TextBlock Text="Notice that the state of the Tab is maintained in the new window. For example, if you toggle the ToggleSwitch ON, it will remain ON in the new window." Style="{ThemeResource BodyTextBlockStyle}" />
<ToggleSwitch x:Name="ControlToggle" Header="Turn on ProgressRing" Margin="0,8" />
<ProgressRing IsActive="{x:Bind ControlToggle.IsOn, Mode=OneWay}" HorizontalAlignment="Left" />
<ToggleSwitch x:Name="ControlToggle" Header="Turn on ProgressRing" Margin="0,8" IsOn="{x:Bind IsInProgress, Mode=TwoWay}" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unclear on why this change is being made & net impact on UX. Can you explain or add screenshot in PR Description.

<ProgressRing IsActive="{x:Bind IsInProgress, Mode=OneWay}" HorizontalAlignment="Left" />
</StackPanel>
</UserControl>
10 changes: 10 additions & 0 deletions WinUIGallery/Samples/SamplePages/TabContentSampleControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace WinUIGallery.SamplePages;
Expand All @@ -8,4 +9,13 @@ public TabContentSampleControl()
{
this.InitializeComponent();
}
public bool IsInProgress
{
get { return (bool)GetValue(IsInProgressProperty); }
set { SetValue(IsInProgressProperty, value); }
}

public static readonly DependencyProperty IsInProgressProperty = DependencyProperty.Register("IsInProgress", typeof(bool), typeof(TabContentSampleControl), new PropertyMetadata(false));


}
34 changes: 24 additions & 10 deletions WinUIGallery/Samples/SamplePages/TabViewWindowingSamplePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@
mc:Ignorable="d">

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TabView
x:Name="Tabs"
VerticalAlignment="Stretch"
AddTabButtonClick="Tabs_AddTabButtonClick"
CanTearOutTabs="True"
ExternalTornOutTabsDropped="Tabs_ExternalTornOutTabsDropped"
ExternalTornOutTabsDropping="Tabs_ExternalTornOutTabsDropping"
TabCloseRequested="Tabs_TabCloseRequested"
TabTearOutRequested="Tabs_TabTearOutRequested"
TabTearOutWindowRequested="Tabs_TabTearOutWindowRequested">
<TabView
x:Name="Tabs"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix indentation and why order of event subscription being changed for all the items (only diff seems addition of TabItemsSource)?

VerticalAlignment="Stretch"
AddTabButtonClick="Tabs_AddTabButtonClick"
TabCloseRequested="Tabs_TabCloseRequested"
CanTearOutTabs="True"
TabTearOutWindowRequested="Tabs_TabTearOutWindowRequested"
TabTearOutRequested="Tabs_TabTearOutRequested"
ExternalTornOutTabsDropping="Tabs_ExternalTornOutTabsDropping"
ExternalTornOutTabsDropped="Tabs_ExternalTornOutTabsDropped"
TabItemsSource="{x:Bind TabItemDataList}">
<TabView.TabStripHeader>
<Grid x:Name="ShellTitleBarInset" Background="Transparent" />
</TabView.TabStripHeader>
<TabView.TabStripFooter>
<Grid x:Name="CustomDragRegion" Background="Transparent" />
</TabView.TabStripFooter>
<TabView.TabItemTemplate>
<DataTemplate x:DataType="local:TabItemData">
<TabViewItem Header="{x:Bind Header}">
<TabViewItem.ContextFlyout>
<MenuFlyout Opening="TabViewContextMenu_Opening" />
</TabViewItem.ContextFlyout>
<TabViewItem.IconSource>
<SymbolIconSource Symbol="Placeholder" />
</TabViewItem.IconSource>
<local:TabContentSampleControl DataContext="{x:Bind Content}" IsInProgress="{x:Bind IsInProgress, Mode=TwoWay}" />
</TabViewItem>
</DataTemplate>
</TabView.TabItemTemplate>
</TabView>
</Grid>
</Page>
Loading