Skip to content

Commit 8c55b4d

Browse files
committed
Simplify
1 parent c21a8f3 commit 8c55b4d

File tree

5 files changed

+55
-121
lines changed

5 files changed

+55
-121
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Microsoft.UI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Input;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Media;
10-
using Microsoft.UI.Xaml.Shapes;
4+
using Microsoft.UI.Xaml.Automation;
115
using Windows.Foundation;
126

137
namespace Files.App.Controls
@@ -93,13 +87,22 @@ internal protected virtual void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem
9387

9488
internal protected virtual void OnLayoutUpdated()
9589
{
96-
if (_itemsRepeater is null || _isEllipsisRendered == _itemsRepeaterLayout.EllipsisIsRendered)
90+
if (_itemsRepeater is null)
9791
return;
9892

9993
_isEllipsisRendered = _itemsRepeaterLayout.EllipsisIsRendered;
10094
if (_ellipsisBreadcrumbBarItem is not null)
101-
{
10295
_ellipsisBreadcrumbBarItem.Visibility = _isEllipsisRendered ? Visibility.Visible : Visibility.Collapsed;
96+
97+
for (int accessibilityIndex = 0, collectionIndex = _itemsRepeaterLayout.IndexAfterEllipsis;
98+
accessibilityIndex < _itemsRepeaterLayout.VisibleItemsCount;
99+
accessibilityIndex++, collectionIndex++)
100+
{
101+
if (_itemsRepeater.TryGetElement(collectionIndex) is { } element)
102+
{
103+
element.SetValue(AutomationProperties.PositionInSetProperty, accessibilityIndex);
104+
element.SetValue(AutomationProperties.SizeOfSetProperty, _itemsRepeaterLayout.VisibleItemsCount);
105+
}
103106
}
104107
}
105108

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.xaml

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
<Setter Property="Template">
2828
<Setter.Value>
2929
<ControlTemplate TargetType="local:BreadcrumbBar">
30-
<Grid MinWidth="{TemplateBinding MinWidth}" ColumnSpacing="2">
30+
<Grid
31+
MinWidth="{TemplateBinding MinWidth}"
32+
ColumnSpacing="2"
33+
TabFocusNavigation="Once"
34+
XYFocusKeyboardNavigation="Enabled">
3135
<Grid.ColumnDefinitions>
3236
<ColumnDefinition Width="Auto" />
3337
<ColumnDefinition Width="Auto" />
@@ -38,13 +42,15 @@
3842
x:Name="PART_RootBreadcrumbBarItem"
3943
Grid.Column="0"
4044
Padding="{StaticResource BreadcrumbBarRootItemPadding}"
45+
AutomationProperties.AccessibilityView="Content"
4146
CornerRadius="{StaticResource BreadcrumbBarRootItemCornerRadius}">
4247
<ContentPresenter Content="{Binding RootItem, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
4348
</local:BreadcrumbBarItem>
4449

4550
<local:BreadcrumbBarItem
4651
x:Name="PART_EllipsisBreadcrumbBarItem"
4752
Grid.Column="1"
53+
AutomationProperties.AccessibilityView="Content"
4854
IsEllipsis="True"
4955
Visibility="Collapsed">
5056
<FontIcon FontSize="{StaticResource BreadcrumbBarEllipsisFontSize}" Glyph="&#xE712;" />
@@ -81,28 +87,34 @@
8187
<Setter Property="VerticalAlignment" Value="Stretch" />
8288
<Setter Property="VerticalContentAlignment" Value="Center" />
8389

84-
<Setter Property="IsTabStop" Value="True" />
90+
<Setter Property="FocusVisualMargin" Value="1" />
91+
<Setter Property="IsTabStop" Value="False" />
8592
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
8693
<Setter Property="Template">
8794
<Setter.Value>
8895
<ControlTemplate TargetType="local:BreadcrumbBarItem">
89-
<Grid x:Name="PART_LayoutRoot" ColumnSpacing="2">
96+
<Grid
97+
x:Name="PART_LayoutRoot"
98+
ColumnSpacing="2"
99+
XYFocusKeyboardNavigation="Enabled">
90100
<Grid.ColumnDefinitions>
91101
<ColumnDefinition x:Name="PART_ContentColumn" Width="Auto" />
92102
<ColumnDefinition x:Name="PART_ChevronColumn" Width="Auto" />
93103
</Grid.ColumnDefinitions>
94104

95105
<!-- Clickable Area -->
96-
<Border
106+
<Button
97107
x:Name="PART_ItemContentButton"
98108
Padding="{TemplateBinding Padding}"
109+
VerticalAlignment="Stretch"
110+
AutomationProperties.AccessibilityView="Raw"
99111
Background="{TemplateBinding Background}"
100112
BorderBrush="{TemplateBinding BorderBrush}"
101113
BorderThickness="{TemplateBinding BorderThickness}"
102-
CornerRadius="{TemplateBinding CornerRadius}">
103-
<Border.BackgroundTransition>
104-
<BrushTransition Duration="0:0:0.083" />
105-
</Border.BackgroundTransition>
114+
Control.IsTemplateFocusTarget="True"
115+
CornerRadius="{TemplateBinding CornerRadius}"
116+
IsTabStop="True"
117+
UseSystemFocusVisuals="True">
106118
<FlyoutBase.AttachedFlyout>
107119
<MenuFlyout
108120
x:Name="PART_ItemEllipsisDropDownMenuFlyout"
@@ -123,6 +135,7 @@
123135
x:Name="PART_ItemContentPresenter"
124136
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
125137
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
138+
AutomationProperties.AccessibilityView="Raw"
126139
Content="{TemplateBinding Content}"
127140
ContentTemplate="{TemplateBinding ContentTemplate}"
128141
ContentTransitions="{TemplateBinding ContentTransitions}"
@@ -132,20 +145,21 @@
132145
Foreground="{ThemeResource BreadcrumbBarForegroundBrush}"
133146
TextLineBounds="Tight" />
134147

135-
</Border>
148+
</Button>
136149

137150
<!-- Chevron -->
138-
<Border
151+
<Button
139152
x:Name="PART_ItemChevronButton"
140153
Grid.Column="1"
141154
Padding="{StaticResource BreadcrumbBarChevronPadding}"
155+
VerticalAlignment="Stretch"
156+
AutomationProperties.AccessibilityView="Content"
142157
Background="{TemplateBinding Background}"
143158
BorderBrush="{TemplateBinding BorderBrush}"
144159
BorderThickness="{TemplateBinding BorderThickness}"
145-
CornerRadius="{StaticResource BreadcrumbBarChevronCornerRaduis}">
146-
<Border.BackgroundTransition>
147-
<BrushTransition Duration="0:0:0.083" />
148-
</Border.BackgroundTransition>
160+
CornerRadius="{StaticResource BreadcrumbBarChevronCornerRaduis}"
161+
IsTabStop="True"
162+
UseSystemFocusVisuals="True">
149163
<FlyoutBase.AttachedFlyout>
150164
<MenuFlyout
151165
x:Name="PART_ItemChevronDropDownMenuFlyout"
@@ -169,6 +183,7 @@
169183
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
170184
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
171185
AnimatedIcon.State="NormalOff"
186+
AutomationProperties.AccessibilityView="Raw"
172187
Foreground="{ThemeResource BreadcrumbBarForegroundBrush}"
173188
MirroredWhenRightToLeft="True"
174189
RenderTransformOrigin="0.5, 0.5">
@@ -181,39 +196,10 @@
181196
<animatedvisuals:AnimatedChevronRightDownSmallVisualSource />
182197
</AnimatedIcon>
183198

184-
</Border>
199+
</Button>
185200

186201
<VisualStateManager.VisualStateGroups>
187202

188-
<VisualStateGroup x:Name="PointerStates">
189-
<VisualState x:Name="PointerNormal" />
190-
191-
<VisualState x:Name="PointerOverItem">
192-
<VisualState.Setters>
193-
<Setter Target="PART_ItemContentButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
194-
<Setter Target="PART_ItemChevronButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
195-
</VisualState.Setters>
196-
</VisualState>
197-
<VisualState x:Name="PointerOverChevron">
198-
<VisualState.Setters>
199-
<Setter Target="PART_ItemChevronButton.Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
200-
</VisualState.Setters>
201-
</VisualState>
202-
203-
<VisualState x:Name="PointerPressedOnItem">
204-
<VisualState.Setters>
205-
<Setter Target="PART_ItemContentButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
206-
<Setter Target="PART_ItemChevronButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
207-
</VisualState.Setters>
208-
</VisualState>
209-
<VisualState x:Name="PointerPressedOnChevron">
210-
<VisualState.Setters>
211-
<Setter Target="PART_ItemChevronButton.Background" Value="{ThemeResource ControlFillColorTertiaryBrush}" />
212-
</VisualState.Setters>
213-
</VisualState>
214-
215-
</VisualStateGroup>
216-
217203
<VisualStateGroup x:Name="ChevronVisibilityStates">
218204
<VisualState x:Name="ChevronVisible" />
219205
<VisualState x:Name="ChevronCollapsed">

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarItem.Events.cs

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,20 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Microsoft.UI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Input;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Media;
10-
using Microsoft.UI.Xaml.Shapes;
11-
124
namespace Files.App.Controls
135
{
146
public partial class BreadcrumbBarItem
157
{
16-
private void ItemButton_PointerEntered(object sender, PointerRoutedEventArgs e)
17-
{
18-
VisualStateManager.GoToState(this, "PointerOverItem", true);
19-
}
20-
21-
private void ItemButton_PointerPressed(object sender, PointerRoutedEventArgs e)
22-
{
23-
VisualStateManager.GoToState(this, "PointerPressedOnItem", true);
24-
}
25-
26-
private void ItemButton_PointerReleased(object sender, PointerRoutedEventArgs e)
8+
private void ItemContentButton_Click(object sender, RoutedEventArgs e)
279
{
2810
OnItemClicked();
29-
30-
VisualStateManager.GoToState(this, "PointerOverItem", true);
31-
}
32-
33-
private void ItemButton_PointerExited(object sender, PointerRoutedEventArgs e)
34-
{
35-
VisualStateManager.GoToState(this, "PointerNormal", true);
3611
}
3712

38-
private void ChevronButton_PointerEntered(object sender, PointerRoutedEventArgs e)
13+
private void ItemChevronButton_Click(object sender, RoutedEventArgs e)
3914
{
40-
VisualStateManager.GoToState(this, "PointerOverChevron", true);
41-
}
42-
43-
private void ChevronButton_PointerPressed(object sender, PointerRoutedEventArgs e)
44-
{
45-
VisualStateManager.GoToState(this, "PointerPressedOnChevron", true);
46-
}
47-
48-
private void ChevronButton_PointerReleased(object sender, PointerRoutedEventArgs e)
49-
{
50-
VisualStateManager.GoToState(this, "PointerOverChevron", true);
51-
5215
FlyoutBase.ShowAttachedFlyout(_itemChevronButton);
5316
}
5417

55-
private void ChevronButton_PointerExited(object sender, PointerRoutedEventArgs e)
56-
{
57-
VisualStateManager.GoToState(this, "PointerNormal", true);
58-
}
59-
6018
private void ChevronDropDownMenuFlyout_Opening(object? sender, object e)
6119
{
6220
if (_ownerRef is null ||
@@ -69,7 +27,7 @@ private void ChevronDropDownMenuFlyout_Opening(object? sender, object e)
6927

7028
private void ChevronDropDownMenuFlyout_Opened(object? sender, object e)
7129
{
72-
VisualStateManager.GoToState(this, "ChevronNormalOn", true);
30+
//VisualStateManager.GoToState(this, "ChevronNormalOn", true);
7331
}
7432

7533
private void ChevronDropDownMenuFlyout_Closed(object? sender, object e)
@@ -81,7 +39,7 @@ private void ChevronDropDownMenuFlyout_Closed(object? sender, object e)
8139

8240
breadcrumbBar.RaiseItemDropDownFlyoutClosed(this, flyout);
8341

84-
VisualStateManager.GoToState(this, "ChevronNormalOff", true);
42+
//VisualStateManager.GoToState(this, "ChevronNormalOff", true);
8543
VisualStateManager.GoToState(this, "PointerNormal", true);
8644
}
8745
}

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarItem.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Microsoft.UI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Input;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Media;
10-
using Microsoft.UI.Xaml.Shapes;
11-
124
namespace Files.App.Controls
135
{
146
public partial class BreadcrumbBarItem : ContentControl
@@ -24,8 +16,8 @@ public partial class BreadcrumbBarItem : ContentControl
2416

2517
private WeakReference<BreadcrumbBar>? _ownerRef;
2618

27-
private Border _itemContentButton = null!;
28-
private Border _itemChevronButton = null!;
19+
private Button _itemContentButton = null!;
20+
private Button _itemChevronButton = null!;
2921
private MenuFlyout _itemEllipsisDropDownMenuFlyout = null!;
3022
private MenuFlyout _itemChevronDropDownMenuFlyout = null!;
3123

@@ -42,9 +34,9 @@ protected override void OnApplyTemplate()
4234
{
4335
base.OnApplyTemplate();
4436

45-
_itemContentButton = GetTemplateChild(TemplatePartName_ItemContentButton) as Border
37+
_itemContentButton = GetTemplateChild(TemplatePartName_ItemContentButton) as Button
4638
?? throw new MissingFieldException($"Could not find {TemplatePartName_ItemContentButton} in the given {nameof(BreadcrumbBarItem)}'s style.");
47-
_itemChevronButton = GetTemplateChild(TemplatePartName_ItemChevronButton) as Border
39+
_itemChevronButton = GetTemplateChild(TemplatePartName_ItemChevronButton) as Button
4840
?? throw new MissingFieldException($"Could not find {TemplatePartName_ItemChevronButton} in the given {nameof(BreadcrumbBarItem)}'s style.");
4941
_itemEllipsisDropDownMenuFlyout = GetTemplateChild(TemplatePartName_ItemEllipsisDropDownMenuFlyout) as MenuFlyout
5042
?? throw new MissingFieldException($"Could not find {TemplatePartName_ItemEllipsisDropDownMenuFlyout} in the given {nameof(BreadcrumbBarItem)}'s style.");
@@ -54,16 +46,8 @@ protected override void OnApplyTemplate()
5446
if (IsEllipsis || IsLastItem)
5547
VisualStateManager.GoToState(this, "ChevronCollapsed", true);
5648

57-
_itemContentButton.PointerEntered += ItemButton_PointerEntered;
58-
_itemContentButton.PointerPressed += ItemButton_PointerPressed;
59-
_itemContentButton.PointerReleased += ItemButton_PointerReleased;
60-
_itemContentButton.PointerExited += ItemButton_PointerExited;
61-
62-
_itemChevronButton.PointerEntered += ChevronButton_PointerEntered;
63-
_itemChevronButton.PointerPressed += ChevronButton_PointerPressed;
64-
_itemChevronButton.PointerReleased += ChevronButton_PointerReleased;
65-
_itemChevronButton.PointerExited += ChevronButton_PointerExited;
66-
49+
_itemContentButton.Click += ItemContentButton_Click;
50+
_itemChevronButton.Click += ItemChevronButton_Click;
6751
_itemChevronDropDownMenuFlyout.Opening += ChevronDropDownMenuFlyout_Opening;
6852
_itemChevronDropDownMenuFlyout.Opened += ChevronDropDownMenuFlyout_Opened;
6953
_itemChevronDropDownMenuFlyout.Closed += ChevronDropDownMenuFlyout_Closed;

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
6161
double accumulatedWidths = 0d;
6262

6363
IndexAfterEllipsis = GetFirstIndexToRender(context);
64+
VisibleItemsCount = 0;
6465

6566
// Go through all items and arrange them
6667
for (int index = 0; index < context.Children.Count; index++)
@@ -79,6 +80,8 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
7980

8081
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
8182
accumulatedWidths += _spacing;
83+
84+
VisibleItemsCount++;
8285
}
8386
}
8487
}

0 commit comments

Comments
 (0)