33using Bible . Alarm . Services . Contracts ;
44using Bible . Alarm . UI ;
55using Bible . Alarm . ViewModels ;
6- using Serilog ;
7- using Microsoft . Extensions . DependencyInjection ;
86
97namespace Bible . Alarm ;
108
@@ -32,17 +30,9 @@ protected override Window CreateWindow(IActivationState? activationState)
3230 // Initialize platform-specific bootstrap helper after ServiceProviderManager is available
3331 InitializePlatformBootstrap ( ) ;
3432
35- // Create a simple window with a basic page for now
36- var window = new Window ( new ContentPage
37- {
38- Title = "Bible Alarm" ,
39- Content = new Label
40- {
41- Text = "Bible Alarm is starting..." ,
42- HorizontalOptions = LayoutOptions . Center ,
43- VerticalOptions = LayoutOptions . Center
44- }
45- } ) ;
33+ // Create a NavigationPage as the root page (proper MAUI pattern)
34+ var navigationPage = new NavigationPage ( ) ;
35+ var window = new Window ( navigationPage ) ;
4636
4737 // Initialize services in background
4838 Task . Run ( async ( ) =>
@@ -51,13 +41,10 @@ protected override Window CreateWindow(IActivationState? activationState)
5141 {
5242 System . Diagnostics . Debug . WriteLine ( "Starting service initialization..." ) ;
5343
54- // Create and store the navigation service for later use
44+ // Get navigation service from DI container
5545 using var scope = _scopeFactory . CreateScope ( ) ;
56- _navigationService = new NavigationService (
57- scope . ServiceProvider . GetRequiredService < ILogger > ( ) ,
58- null , // Will be set when we have proper navigation
59- _scopeFactory ) ;
60- System . Diagnostics . Debug . WriteLine ( "NavigationService created!" ) ;
46+ _navigationService = scope . ServiceProvider . GetRequiredService < INavigationService > ( ) ;
47+ System . Diagnostics . Debug . WriteLine ( "NavigationService retrieved from DI!" ) ;
6148
6249 // Initialize the home page
6350 await InitializeHomePage ( window ) ;
@@ -84,11 +71,22 @@ private async Task InitializeHomePage(Window window)
8471 System . Diagnostics . Debug . WriteLine ( "InitializeHomePage called!" ) ;
8572 using var scope = _scopeFactory . CreateScope ( ) ;
8673 var homePage = new Home { BindingContext = scope . ServiceProvider . GetRequiredService < HomeViewModel > ( ) } ;
87-
88- // Set the main page to the home page
89- window . Page = homePage ;
90- System . Diagnostics . Debug . WriteLine ( "Home page set!" ) ;
91-
74+
75+ // Get the NavigationPage from the window
76+ if ( window . Page is NavigationPage navigationPage )
77+ {
78+ // Push the home page to the navigation stack
79+ await navigationPage . PushAsync ( homePage ) ;
80+ System . Diagnostics . Debug . WriteLine ( "Home page pushed to navigation stack!" ) ;
81+
82+ // Set the navigation instance for the NavigationService
83+ if ( _navigationService != null )
84+ {
85+ _navigationService . SetNavigation ( navigationPage . Navigation ) ;
86+ System . Diagnostics . Debug . WriteLine ( "Navigation instance set!" ) ;
87+ }
88+ }
89+
9290 // Add a small delay to ensure proper initialization
9391 await Task . Delay ( 100 ) ;
9492 }
0 commit comments