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

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

@ -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,8 +1,8 @@
 <?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">
<Grid RowDefinitions="Auto, Auto, *, Auto" ColumnDefinitions="*, *"> <Grid RowDefinitions="Auto, Auto, *, Auto" ColumnDefinitions="*, *">
<!-- Пути --> <!-- Пути -->

Loading…
Cancel
Save