Initial commit

This commit is contained in:
2026-08-22 19:11:00 +03:00 Unverified
commit db368674d4
74 changed files with 2739 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using WinWARP.Core.Services;
namespace WinWARP.Ui.Services;
public class NavigationService : INavigationService
{
private readonly Dictionary<Type, Type> _mappings = new();
private Frame _frame;
public void Configure(Type viewModelType, Type pageType)
{
_mappings[viewModelType] = pageType;
_mappings[pageType] = viewModelType;
}
public void RegisterFrame(Frame frame)
{
_frame = frame;
_frame.Navigated += OnFrameNavigated;
}
public bool CanGoBack => _frame?.CanGoBack ?? false;
public void GoBack()
{
if (CanGoBack)
{
_frame.GoBack();
}
}
public void NavigateTo<TViewModel>(object parameter = null) where TViewModel : class
{
var viewModelType = typeof(TViewModel);
if (!_mappings.TryGetValue(viewModelType, out var pageType))
{
throw new ArgumentException($"No registered page found for ViewModel: {viewModelType.FullName}");
}
if (_frame != null)
{
_frame.Navigate(pageType, parameter);
}
}
public Type CurrentViewModelType
{
get; private set;
}
public event EventHandler<Type> NavigatedToViewModel;
private void OnFrameNavigated(object sender, NavigationEventArgs e)
{
var pageType = e.SourcePageType;
if (_mappings.TryGetValue(pageType, out var viewModelType))
{
CurrentViewModelType = viewModelType;
NavigatedToViewModel?.Invoke(this, viewModelType);
}
}
}