11// Copyright (c) Files Community
22// Licensed under the MIT License.
33
4- using CommunityToolkit . WinUI ;
54using Microsoft . UI ;
65using Microsoft . UI . Xaml ;
76using Microsoft . UI . Xaml . Controls ;
87using Microsoft . UI . Xaml . Input ;
98using Microsoft . UI . Xaml . Markup ;
109using Microsoft . UI . Xaml . Media ;
1110using Microsoft . UI . Xaml . Shapes ;
11+ using Windows . Foundation ;
1212
1313namespace 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}
0 commit comments