1
+ using System . ComponentModel ;
2
+ using Maui . Controls . Sample . Issues ;
3
+ using Microsoft . Maui ;
4
+ using Microsoft . Maui . Controls ;
5
+
6
+ namespace Controls . TestCases . Issues ;
7
+
8
+ [ Issue ( IssueTracker . Github , 12500 , "Shell does not always raise Navigating event on Windows" , PlatformAffected . UWP ) ]
9
+ public class Issue12500 : Shell
10
+ {
11
+ private NavigationViewModel _viewModel ;
12
+ public Issue12500 ( )
13
+ {
14
+ this . FlyoutBehavior = FlyoutBehavior . Disabled ;
15
+
16
+ _viewModel = new NavigationViewModel ( ) ;
17
+
18
+ // Create TabBar
19
+ var tabBar = new TabBar ( ) ;
20
+
21
+ // Add ShellContent for MainPage
22
+ tabBar . Items . Add ( new ShellContent
23
+ {
24
+ Title = "Hello, World!" ,
25
+ Route = "MainPage" ,
26
+ ContentTemplate = new DataTemplate ( ( ) => new Issue12500Main { BindingContext = _viewModel } )
27
+ } ) ;
28
+ // Add ShellContent for EventsPage
29
+ tabBar . Items . Add ( new ShellContent
30
+ {
31
+ Title = "Events" ,
32
+ Route = "EventPage" ,
33
+ ContentTemplate = new DataTemplate ( ( ) => new Issue12500EventPage { BindingContext = _viewModel } )
34
+ } ) ;
35
+
36
+ // Add TabBar to Shell
37
+ this . Items . Add ( tabBar ) ;
38
+ }
39
+ protected override void OnNavigating ( ShellNavigatingEventArgs args )
40
+ {
41
+ base . OnNavigating ( args ) ;
42
+ string targetPageRoute = args . Target . Location . ToString ( ) ;
43
+
44
+ // Update ViewModel with new navigation text
45
+ _viewModel . LabelText = $ "Navigating to { targetPageRoute } ";
46
+
47
+ }
48
+ }
49
+ public class Issue12500EventPage : ContentPage
50
+ {
51
+ public Issue12500EventPage ( )
52
+ {
53
+ var label = new Label
54
+ {
55
+ AutomationId = "Issue12500EventPage" ,
56
+ FontSize = 24 ,
57
+ HorizontalOptions = LayoutOptions . Center ,
58
+ VerticalOptions = LayoutOptions . Center
59
+ } ;
60
+ label . SetBinding ( Label . TextProperty , nameof ( NavigationViewModel . LabelText ) ) ; // Bind to ViewModel
61
+
62
+ Content = new VerticalStackLayout
63
+ {
64
+ Children = { label }
65
+ } ;
66
+ }
67
+ }
68
+
69
+ public class Issue12500Main : ContentPage
70
+ {
71
+ public Issue12500Main ( )
72
+ {
73
+ var label = new Label
74
+ {
75
+ AutomationId = "Issue12500MainPage" ,
76
+ FontSize = 24 ,
77
+ HorizontalOptions = LayoutOptions . Center ,
78
+ VerticalOptions = LayoutOptions . Center
79
+ } ;
80
+ label . SetBinding ( Label . TextProperty , nameof ( NavigationViewModel . LabelText ) ) ; // Bind to ViewModel
81
+
82
+ Content = new VerticalStackLayout
83
+ {
84
+ Children = { label }
85
+ } ;
86
+ }
87
+ }
88
+
89
+
90
+ public class NavigationViewModel : INotifyPropertyChanged
91
+ {
92
+ private string _labelText ;
93
+
94
+ public string LabelText
95
+ {
96
+ get => _labelText ;
97
+ set
98
+ {
99
+ if ( _labelText != value )
100
+ {
101
+ _labelText = value ;
102
+ OnPropertyChanged ( nameof ( LabelText ) ) ;
103
+ }
104
+ }
105
+ }
106
+
107
+ public event PropertyChangedEventHandler PropertyChanged ;
108
+
109
+ protected virtual void OnPropertyChanged ( string propertyName )
110
+ {
111
+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
112
+ }
113
+ }
0 commit comments