mirror of
https://github.com/PrismLibrary/Prism.git
synced 2026-10-20 07:22:21 +08:00
aac688c354
Migrates the Uno Platform E2E sample application from a multi-project structure to the recommended single-project architecture. This update consolidates platform-specific heads into the main `HelloWorld` project and introduces a new `Playground.Module` to showcase Prism for Uno.WinUI features like regions, dialogs, and modularity within the streamlined project setup. It also updates the target framework to .NET 10.
91 lines
3.0 KiB
C#
91 lines
3.0 KiB
C#
using System.Collections.Specialized;
|
|
|
|
namespace Playground.Module.ViewModels;
|
|
|
|
internal class RegionLabViewModel : BindableBase, IRegionAware
|
|
{
|
|
private readonly IRegionManager _regionManager;
|
|
private IRegion? _detailRegion;
|
|
|
|
public RegionLabViewModel(IRegionManager regionManager)
|
|
{
|
|
_regionManager = regionManager;
|
|
OpenAlphaCommand = new DelegateCommand(() =>
|
|
_regionManager.RequestNavigate("DetailRegion", "RegionDetailAlphaView"),
|
|
() => _regionManager.Regions.ContainsRegionWithName("DetailRegion"));
|
|
OpenBetaCommand = new DelegateCommand(() =>
|
|
_regionManager.RequestNavigate("DetailRegion", "RegionDetailBetaView"),
|
|
() => _regionManager.Regions.ContainsRegionWithName("DetailRegion"));
|
|
GoBackDetailCommand = new DelegateCommand(
|
|
() => _detailRegion?.NavigationService.Journal.GoBack(),
|
|
() => _detailRegion?.NavigationService.Journal.CanGoBack == true);
|
|
}
|
|
|
|
public DelegateCommand OpenAlphaCommand { get; }
|
|
|
|
public DelegateCommand OpenBetaCommand { get; }
|
|
|
|
public DelegateCommand GoBackDetailCommand { get; }
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
_regionManager.Regions.CollectionChanged += OnRegionsCollectionChanged;
|
|
TryAttachDetailRegion();
|
|
}
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext) => true;
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
{
|
|
_regionManager.Regions.CollectionChanged -= OnRegionsCollectionChanged;
|
|
DetachDetailNavigated();
|
|
}
|
|
|
|
private void OnRegionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
TryAttachDetailRegion();
|
|
}
|
|
|
|
private void TryAttachDetailRegion()
|
|
{
|
|
if (!_regionManager.Regions.ContainsRegionWithName("DetailRegion"))
|
|
{
|
|
DetachDetailNavigated();
|
|
OpenAlphaCommand.RaiseCanExecuteChanged();
|
|
OpenBetaCommand.RaiseCanExecuteChanged();
|
|
return;
|
|
}
|
|
|
|
var region = _regionManager.Regions["DetailRegion"];
|
|
if (ReferenceEquals(_detailRegion, region))
|
|
{
|
|
OpenAlphaCommand.RaiseCanExecuteChanged();
|
|
OpenBetaCommand.RaiseCanExecuteChanged();
|
|
return;
|
|
}
|
|
|
|
DetachDetailNavigated();
|
|
_detailRegion = region;
|
|
_detailRegion.NavigationService.Navigated += OnDetailNavigated;
|
|
OpenAlphaCommand.RaiseCanExecuteChanged();
|
|
OpenBetaCommand.RaiseCanExecuteChanged();
|
|
GoBackDetailCommand.RaiseCanExecuteChanged();
|
|
}
|
|
|
|
private void DetachDetailNavigated()
|
|
{
|
|
if (_detailRegion is not null)
|
|
{
|
|
_detailRegion.NavigationService.Navigated -= OnDetailNavigated;
|
|
_detailRegion = null;
|
|
}
|
|
|
|
GoBackDetailCommand.RaiseCanExecuteChanged();
|
|
}
|
|
|
|
private void OnDetailNavigated(object? sender, RegionNavigationEventArgs e)
|
|
{
|
|
GoBackDetailCommand.RaiseCanExecuteChanged();
|
|
}
|
|
}
|