优化更新代码,添加界面功能并整合
This commit is contained in:
93
WPFluent/Services/NavigationService.cs
Normal file
93
WPFluent/Services/NavigationService.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Abstractions;
|
||||
using WPFluent.Controls;
|
||||
|
||||
namespace WPFluent;
|
||||
|
||||
/// <summary>
|
||||
/// A service that provides methods related to navigation.
|
||||
/// </summary>
|
||||
public partial class NavigationService(INavigationViewPageProvider pageProvider) : INavigationService
|
||||
{
|
||||
protected void ThrowIfNavigationControlIsNull()
|
||||
{
|
||||
if(NavigationControl is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(NavigationControl));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the control representing navigation.
|
||||
/// </summary>
|
||||
protected INavigationView? NavigationControl { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public INavigationView GetNavigationControl()
|
||||
{ return NavigationControl ?? throw new ArgumentNullException(nameof(NavigationControl)); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool GoBack()
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.GoBack();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Navigate(Type pageType)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.Navigate(pageType);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Navigate(string pageTag)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.Navigate(pageTag);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Navigate(Type pageType, object? dataContext)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.Navigate(pageType, dataContext);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Navigate(string pageTag, object? dataContext)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.Navigate(pageTag, dataContext);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool NavigateWithHierarchy(Type pageType)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.NavigateWithHierarchy(pageType);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool NavigateWithHierarchy(Type pageType, object? dataContext)
|
||||
{
|
||||
ThrowIfNavigationControlIsNull();
|
||||
|
||||
return NavigationControl!.NavigateWithHierarchy(pageType, dataContext);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SetNavigationControl(INavigationView navigation)
|
||||
{
|
||||
NavigationControl = navigation;
|
||||
NavigationControl.SetPageProviderService(pageProvider);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user