Click or drag to resize

NavigationService Class

Provides ways to show windows, user controls, dialogs and more.
Inheritance Hierarchy
SystemObject
  SniffCore.NavigationNavigationService

Namespace:  SniffCore.Navigation
Assembly:  SniffCore.Navigation (in SniffCore.Navigation.dll) Version: 1.6.0
Syntax
C#
public class NavigationService : INavigationService

The NavigationService type exposes the following members.

Constructors
  NameDescription
Public methodNavigationService
Creates a new instance of NavigationPresenter.
Top
Methods
  NameDescription
Public methodClose
Closes the open window known by its key. If the window was modal, the DialogResult will be null.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodSetDialogResult
Sets the dialog result of the open modal window by its key. That does not work for non modal windows.
Public methodShowControlAsync
Shows a new user control by its control key into the NavigationPresenter known by its id.
Public methodShowDialog(IBrowseFolderData)
Shows the browse folder dialog.
Public methodShowDialog(IColorPickerData)
Shows the color picker dialog.
Public methodShowDialog(IFontPickerData)
Shows the font picker dialog.
Public methodShowDialog(IOpenFileData)
Shows the open file dialog.
Public methodShowDialog(ISaveFileData)
Shows the save file dialog.
Public methodShowDialog(Object, IBrowseFolderData)
Shows the browse folder dialog.
Public methodShowDialog(Object, IColorPickerData)
Shows the color picker dialog.
Public methodShowDialog(Object, IFontPickerData)
Shows the font picker dialog.
Public methodShowDialog(Object, IOpenFileData)
Shows the open file dialog.
Public methodShowDialog(Object, ISaveFileData)
Shows the save file dialog.
Public methodShowMessageBox(String)
Shows the message box.
Public methodShowMessageBox(Object, String)
Shows the message box.
Public methodShowMessageBox(String, String)
Shows the message box.
Public methodShowMessageBox(Object, String, String)
Shows the message box.
Public methodShowMessageBox(String, String, MessageBoxButton)
Shows the message box.
Public methodShowMessageBox(Object, String, String, MessageBoxButton)
Shows the message box.
Public methodShowMessageBox(String, String, MessageBoxButton, IMessageBoxOptions)
Shows the message box.
Public methodShowMessageBox(Object, String, String, MessageBoxButton, IMessageBoxOptions)
Shows the message box.
Public methodShowModalWindowAsync(Object, Object)
Shows a modal window.
Public methodShowModalWindowAsync(Object, Object, Object)
Shows a modal window.
Public methodShowWindowAsync(Object, Object)
Shows a non modal window.
Public methodShowWindowAsync(Object, Object, Object)
Shows a non modal window.
Public methodToString (Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodIsNullOrEmpty
Checks if the object is null or an empty string.
(Defined by ObjectEx.)
Public Extension MethodIsNullOrWhiteSpace
Checks if the object is null, an empty string or a string which consists of whitespace (or tabs) only.
(Defined by ObjectEx.)
Top
Examples
C#
public void Bootstrapper
{
    IUnityContainer _unityContainer;

    public Bootstrapper()
    {
        _unityContainer = new UnityContainer();
        _unityContainer.RegisterSingleton<IWindowProvider, WindowProvider>();
        _unityContainer.RegisterType<IDialogProvider, DialogProvider>();
        _unityContainer.RegisterType<IMessageBoxProvider, MessageBoxProvider>();
        _unityContainer.RegisterType<IPleaseWaitProvider, PleaseWaitProvider>();
        _unityContainer.RegisterType<INavigationService, NavigationService>();

        RegisterViews();
    }

    public void RegisterViews()
    {
        var windowProvider = (WindowProvider) _unityContainer.Resolve<IWindowProvider>();

        windowProvider.RegisterWindow<MainView>("MainView");
        windowProvider.RegisterWindow<SubView>("SubView");

        windowProvider.RegisterControl<DialogsView>("DialogsView");
        windowProvider.RegisterControl<DisplayControlView>("DisplayControlView");
    }
}
C#
public class WindowViewModel : ObservableObject, IAsyncLoader
{
    public async Task LoadAsync()
    {
        // Loads the data as soon the window got shown.
        await Task.CompletedTask;
    }
}
C#
public void ViewModel : ObservableObject
{
    private INavigationService _navigationService;

    public ViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
    }

    public async Task ShowWindow()
    {
        var vm = new WindowViewModel();
        await _navigationService.ShowModalWindow("MainView", vm);
    }
}
C#
[TestFixture]
public class ViewModelTests
{
    private Mock<INavigationService> _navigationService;
    private ViewModel _target;

    [SetUp]
    public void Setup()
    {
        _navigationService = new Mock<INavigationService>();
        _target = new ViewModel(_navigationService.Object);
    }

    [Test]
    public void ShowWindow_Called_ShowsTheWindow()
    {
        _target.ShowWindow();

        _navigationService.Verify(x => x.ShowModalWindow(Args.Any<string>(), Args.Any<object>()), Times.Once);
    }
}
See Also