правка создания

main
Пилипенко Андрей Борисович 3 weeks ago
parent f630287d35
commit 354adb75da

@ -8,21 +8,26 @@ public partial class App : Application
public App() public App()
{ {
InitializeComponent(); InitializeComponent();
}
var services = new ServiceCollection(); protected override Window CreateWindow(IActivationState? activationState)
ConfigureServices(services); {
var serviceProvider = services.BuildServiceProvider(); // Создаем сервисы непосредственно в CreateWindow
var fileService = new FileSystemService();
var panelManager = new PanelManager();
var fileOperations = new FileOperations();
var keyboardService = new KeyboardService();
var pathHelper = new PathHelper();
MainPage = serviceProvider.GetService<MainPage>(); var mainPage = new MainPage(fileService, panelManager, fileOperations, keyboardService, pathHelper);
} var window = new Window(new AppShell(mainPage));
private void ConfigureServices(ServiceCollection services) // Обработка закрытия окна
window.Destroying += (s, e) =>
{ {
services.AddSingleton<IFileSystemService, FileSystemService>(); // keyboardService?.Dispose();
services.AddSingleton<IPanelManager, PanelManager>(); };
services.AddSingleton<IFileOperations, FileOperations>();
services.AddSingleton<IKeyboardService, KeyboardService>(); return window;
services.AddSingleton<IPathHelper, PathHelper>();
services.AddSingleton<MainPage>();
} }
} }

@ -3,12 +3,10 @@
x:Class="CommanderApp.AppShell" x:Class="CommanderApp.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CommanderApp" Title="MAUI Commander">
Title="MAUI Comander">
<ShellContent <ShellContent
x:Name="MainContent"
Title="Home" Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" /> Route="MainPage" />
</Shell> </Shell>

@ -2,9 +2,10 @@
{ {
public partial class AppShell : Shell public partial class AppShell : Shell
{ {
public AppShell() public AppShell(MainPage mainPage)
{ {
InitializeComponent(); InitializeComponent();
MainContent.Content = mainPage;
} }
} }
} }

@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CommanderApp.MainPage" x:Class="CommanderApp.MainPage"
Title="MAUI Commander"> Title="MAUI Commander">

Loading…
Cancel
Save