@@ -24,6 +24,11 @@ public sealed partial class BreadcrumbBarItem : ContentControl
2424 private Border _itemButton = null ! ;
2525 private Border _chevronButton = null ! ;
2626
27+ private bool _pointerOverItem ;
28+ private bool _pointerOverChevron ;
29+ private bool _pointerPressedOnItem ;
30+ private bool _pointerPressedOnChevron ;
31+
2732 // Constructor
2833
2934 public BreadcrumbBarItem ( )
@@ -35,39 +40,113 @@ public BreadcrumbBarItem()
3540
3641 protected override void OnApplyTemplate ( )
3742 {
43+ base . OnApplyTemplate ( ) ;
44+
3845 _itemButton = GetTemplateChild ( _itemButtonName ) as Border
3946 ?? throw new MissingFieldException ( $ "Could not find { _itemButtonName } in the given { nameof ( BreadcrumbBarItem ) } 's style.") ;
4047 _chevronButton = GetTemplateChild ( _chevronButtonName ) as Border
4148 ?? throw new MissingFieldException ( $ "Could not find { _chevronButtonName } in the given { nameof ( BreadcrumbBarItem ) } 's style.") ;
4249
43- _itemButton . PointerEntered += BreadcrumbBarItem_PointerEntered ;
44- _itemButton . PointerPressed += BreadcrumbBarItem_PointerPressed ;
45- _itemButton . PointerReleased += BreadcrumbBarItem_PointerReleased ;
46- _itemButton . PointerExited += BreadcrumbBarItem_PointerExited ;
50+ _itemButton . PointerEntered += ItemButton_PointerEntered ;
51+ _itemButton . PointerPressed += ItemButton_PointerPressed ;
52+ _itemButton . PointerReleased += ItemButton_PointerReleased ;
53+ _itemButton . PointerExited += ItemButton_PointerExited ;
4754
48- base . OnApplyTemplate ( ) ;
55+ _chevronButton . PointerEntered += ChevronButton_PointerEntered ;
56+ _chevronButton . PointerPressed += ChevronButton_PointerPressed ;
57+ _chevronButton . PointerReleased += ChevronButton_PointerReleased ;
58+ _chevronButton . PointerExited += ChevronButton_PointerExited ;
59+
60+ UpdateVisualStates ( ) ;
61+ }
62+
63+ private void UpdateVisualStates ( )
64+ {
65+ if ( _pointerPressedOnItem || _pointerOverItem )
66+ {
67+ VisualStateManager . GoToState (
68+ this ,
69+ _pointerPressedOnItem ? "PointerPressedOnItem" : _pointerOverItem ? "PointerOverItem" : "PointerNormal" ,
70+ true ) ;
71+
72+ return ;
73+ }
74+
75+ if ( _pointerPressedOnChevron || _pointerOverChevron )
76+ {
77+ VisualStateManager . GoToState (
78+ this ,
79+ _pointerPressedOnChevron ? "PointerPressedOnChevron" : _pointerOverChevron ? "PointerOverChevron" : "PointerNormal" ,
80+ true ) ;
81+
82+ return ;
83+ }
84+
85+ VisualStateManager . GoToState ( this , "PointerNormal" , true ) ;
4986 }
5087
5188 // Event methods
5289
53- private void BreadcrumbBarItem_PointerEntered ( object sender , PointerRoutedEventArgs e )
90+ private void ItemButton_PointerEntered ( object sender , PointerRoutedEventArgs e )
5491 {
55- VisualStateManager . GoToState ( this , "PointerOverItem" , true ) ;
92+ _pointerOverItem = true ;
93+ _pointerPressedOnItem = false ;
94+
95+ UpdateVisualStates ( ) ;
5696 }
5797
58- private void BreadcrumbBarItem_PointerPressed ( object sender , PointerRoutedEventArgs e )
98+ private void ItemButton_PointerPressed ( object sender , PointerRoutedEventArgs e )
5999 {
60- VisualStateManager . GoToState ( this , "PointerPressedOnItem" , true ) ;
100+ _pointerOverItem = false ;
101+ _pointerPressedOnItem = true ;
102+
103+ UpdateVisualStates ( ) ;
61104 }
62105
63- private void BreadcrumbBarItem_PointerReleased ( object sender , PointerRoutedEventArgs e )
106+ private void ItemButton_PointerReleased ( object sender , PointerRoutedEventArgs e )
64107 {
65- VisualStateManager . GoToState ( this , "PointerOverItem" , true ) ;
108+ _pointerOverItem = true ;
109+ _pointerPressedOnItem = false ;
110+
111+ UpdateVisualStates ( ) ;
66112 }
67113
68- private void BreadcrumbBarItem_PointerExited ( object sender , PointerRoutedEventArgs e )
114+ private void ItemButton_PointerExited ( object sender , PointerRoutedEventArgs e )
69115 {
70- VisualStateManager . GoToState ( this , "PointerNormal" , true ) ;
116+ _pointerOverItem = _pointerPressedOnItem = false ;
117+
118+ UpdateVisualStates ( ) ;
119+ }
120+
121+ private void ChevronButton_PointerEntered ( object sender , PointerRoutedEventArgs e )
122+ {
123+ _pointerOverChevron = true ;
124+ _pointerPressedOnChevron = false ;
125+
126+ UpdateVisualStates ( ) ;
127+ }
128+
129+ private void ChevronButton_PointerPressed ( object sender , PointerRoutedEventArgs e )
130+ {
131+ _pointerOverChevron = false ;
132+ _pointerPressedOnChevron = true ;
133+
134+ UpdateVisualStates ( ) ;
135+ }
136+
137+ private void ChevronButton_PointerReleased ( object sender , PointerRoutedEventArgs e )
138+ {
139+ _pointerOverChevron = true ;
140+ _pointerPressedOnChevron = false ;
141+
142+ UpdateVisualStates ( ) ;
143+ }
144+
145+ private void ChevronButton_PointerExited ( object sender , PointerRoutedEventArgs e )
146+ {
147+ _pointerOverChevron = _pointerPressedOnChevron = false ;
148+
149+ UpdateVisualStates ( ) ;
71150 }
72151 }
73152}
0 commit comments