Skip to content

Commit de7b132

Browse files
committed
Added events for flyout
1 parent 1f0fb24 commit de7b132

File tree

4 files changed

+115
-73
lines changed

4 files changed

+115
-73
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@
7878
<BrushTransition Duration="0:0:0.083" />
7979
</Border.BackgroundTransition>
8080
<FlyoutBase.AttachedFlyout>
81-
<MenuFlyout Placement="Bottom">
81+
<MenuFlyout
82+
x:Name="PART_ChevronDropDownMenuFlyout"
83+
Placement="Bottom"
84+
ScrollViewer.VerticalScrollBarVisibility="Auto"
85+
ScrollViewer.VerticalScrollMode="Auto">
8286
<MenuFlyout.MenuFlyoutPresenterStyle>
8387
<Style TargetType="MenuFlyoutPresenter">
8488
<Setter Property="MaxHeight" Value="400" />
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
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+
12+
namespace Files.App.Controls
13+
{
14+
public sealed partial class BreadcrumbBarItem : ContentControl
15+
{
16+
private void ItemButton_PointerEntered(object sender, PointerRoutedEventArgs e)
17+
{
18+
_pointerOverItem = true;
19+
_pointerPressedOnItem = false;
20+
21+
UpdateVisualStates();
22+
}
23+
24+
private void ItemButton_PointerPressed(object sender, PointerRoutedEventArgs e)
25+
{
26+
_pointerOverItem = false;
27+
_pointerPressedOnItem = true;
28+
29+
UpdateVisualStates();
30+
}
31+
32+
private void ItemButton_PointerReleased(object sender, PointerRoutedEventArgs e)
33+
{
34+
_pointerOverItem = true;
35+
_pointerPressedOnItem = false;
36+
37+
UpdateVisualStates();
38+
}
39+
40+
private void ItemButton_PointerExited(object sender, PointerRoutedEventArgs e)
41+
{
42+
_pointerOverItem = _pointerPressedOnItem = false;
43+
44+
UpdateVisualStates();
45+
}
46+
47+
private void ChevronButton_PointerEntered(object sender, PointerRoutedEventArgs e)
48+
{
49+
_pointerOverChevron = true;
50+
_pointerPressedOnChevron = false;
51+
52+
UpdateVisualStates();
53+
}
54+
55+
private void ChevronButton_PointerPressed(object sender, PointerRoutedEventArgs e)
56+
{
57+
_pointerOverChevron = false;
58+
_pointerPressedOnChevron = true;
59+
60+
UpdateVisualStates();
61+
}
62+
63+
private void ChevronButton_PointerReleased(object sender, PointerRoutedEventArgs e)
64+
{
65+
_pointerOverChevron = true;
66+
_pointerPressedOnChevron = false;
67+
68+
UpdateVisualStates();
69+
70+
TryOpenFlyout();
71+
}
72+
73+
private void ChevronButton_PointerExited(object sender, PointerRoutedEventArgs e)
74+
{
75+
_pointerOverChevron = _pointerPressedOnChevron = false;
76+
77+
UpdateVisualStates();
78+
}
79+
80+
private void ChevronDropDownMenuFlyout_Opening(object? sender, object e)
81+
{
82+
Opening?.Invoke(sender, e);
83+
}
84+
85+
private void ChevronDropDownMenuFlyout_Closed(object? sender, object e)
86+
{
87+
Closed?.Invoke(sender, e);
88+
}
89+
}
90+
}
Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using CommunityToolkit.WinUI;
54
using Microsoft.UI;
65
using Microsoft.UI.Xaml;
76
using Microsoft.UI.Xaml.Controls;
87
using Microsoft.UI.Xaml.Input;
98
using Microsoft.UI.Xaml.Markup;
109
using Microsoft.UI.Xaml.Media;
1110
using Microsoft.UI.Xaml.Shapes;
11+
using Windows.Foundation;
1212

1313
namespace Files.App.Controls
1414
{
@@ -18,17 +18,24 @@ public sealed partial class BreadcrumbBarItem : ContentControl
1818

1919
private const string _itemButtonName = "PART_ItemButton";
2020
private const string _chevronButtonName = "PART_ChevronButton";
21+
private const string _chevronDropDownMenuFlyoutName = "PART_ChevronDropDownMenuFlyout";
2122

2223
// Fields
2324

2425
private Border _itemButton = null!;
2526
private Border _chevronButton = null!;
27+
private MenuFlyout _chevronDropDownMenuFlyout = null!;
2628

2729
private bool _pointerOverItem;
2830
private bool _pointerOverChevron;
2931
private bool _pointerPressedOnItem;
3032
private bool _pointerPressedOnChevron;
3133

34+
// Events
35+
36+
public event EventHandler<object>? Opening;
37+
public event EventHandler<object>? Closed;
38+
3239
// Constructor
3340

3441
public BreadcrumbBarItem()
@@ -46,6 +53,8 @@ protected override void OnApplyTemplate()
4653
?? throw new MissingFieldException($"Could not find {_itemButtonName} in the given {nameof(BreadcrumbBarItem)}'s style.");
4754
_chevronButton = GetTemplateChild(_chevronButtonName) as Border
4855
?? throw new MissingFieldException($"Could not find {_chevronButtonName} in the given {nameof(BreadcrumbBarItem)}'s style.");
56+
_chevronDropDownMenuFlyout = GetTemplateChild(_chevronDropDownMenuFlyoutName) as MenuFlyout
57+
?? throw new MissingFieldException($"Could not find {_chevronDropDownMenuFlyoutName} in the given {nameof(BreadcrumbBarItem)}'s style.");
4958

5059
_itemButton.PointerEntered += ItemButton_PointerEntered;
5160
_itemButton.PointerPressed += ItemButton_PointerPressed;
@@ -57,6 +66,9 @@ protected override void OnApplyTemplate()
5766
_chevronButton.PointerReleased += ChevronButton_PointerReleased;
5867
_chevronButton.PointerExited += ChevronButton_PointerExited;
5968

69+
_chevronDropDownMenuFlyout.Opening += ChevronDropDownMenuFlyout_Opening;
70+
_chevronDropDownMenuFlyout.Closed += ChevronDropDownMenuFlyout_Closed;
71+
6072
UpdateVisualStates();
6173
}
6274

@@ -88,72 +100,8 @@ private void UpdateVisualStates()
88100
private void TryOpenFlyout()
89101
{
90102
FlyoutBase.ShowAttachedFlyout(_chevronButton);
91-
}
92-
93-
// Event methods
94-
95-
private void ItemButton_PointerEntered(object sender, PointerRoutedEventArgs e)
96-
{
97-
_pointerOverItem = true;
98-
_pointerPressedOnItem = false;
99-
100-
UpdateVisualStates();
101-
}
102-
103-
private void ItemButton_PointerPressed(object sender, PointerRoutedEventArgs e)
104-
{
105-
_pointerOverItem = false;
106-
_pointerPressedOnItem = true;
107103

108-
UpdateVisualStates();
109-
}
110-
111-
private void ItemButton_PointerReleased(object sender, PointerRoutedEventArgs e)
112-
{
113-
_pointerOverItem = true;
114-
_pointerPressedOnItem = false;
115-
116-
UpdateVisualStates();
117-
}
118-
119-
private void ItemButton_PointerExited(object sender, PointerRoutedEventArgs e)
120-
{
121-
_pointerOverItem = _pointerPressedOnItem = false;
122-
123-
UpdateVisualStates();
124-
}
125-
126-
private void ChevronButton_PointerEntered(object sender, PointerRoutedEventArgs e)
127-
{
128-
_pointerOverChevron = true;
129-
_pointerPressedOnChevron = false;
130-
131-
UpdateVisualStates();
132-
}
133-
134-
private void ChevronButton_PointerPressed(object sender, PointerRoutedEventArgs e)
135-
{
136-
_pointerOverChevron = false;
137-
_pointerPressedOnChevron = true;
138-
139-
UpdateVisualStates();
140-
}
141-
142-
private void ChevronButton_PointerReleased(object sender, PointerRoutedEventArgs e)
143-
{
144-
_pointerOverChevron = true;
145-
_pointerPressedOnChevron = false;
146-
147-
UpdateVisualStates();
148-
149-
TryOpenFlyout();
150-
}
151-
152-
private void ChevronButton_PointerExited(object sender, PointerRoutedEventArgs e)
153-
{
154-
_pointerOverChevron = _pointerPressedOnChevron = false;
155-
156-
UpdateVisualStates();
104+
VisualStateManager.GoToState(this, "PointerNormal", true);
157105
}
158106
}
159107
}

tests/Files.App.UITests/Views/BreadcrumbBarPage.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public BreadcrumbBarPage()
1818

1919
DummyItems2 =
2020
[
21-
new("Path1", [ new("Children1"), new("Children2") ]),
22-
new("Path1", [ new("Children1"), new("Children2") ]),
23-
new("Path1", [ new("Children1"), new("Children2") ]),
24-
new("Path1", [ new("Children1"), new("Children2") ]),
25-
new("Path1", [ new("Children1"), new("Children2") ]),
26-
new("Path1", [ new("Children1"), new("Children2") ]),
21+
new("Path1"),
22+
new("Path1"),
23+
new("Path1"),
24+
new("Path1"),
25+
new("Path1"),
26+
new("Path1"),
2727
];
2828
}
2929
}

0 commit comments

Comments
 (0)