94 lines
2.3 KiB
C#
94 lines
2.3 KiB
C#
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|