123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- namespace GDNXFD.Alert.Config.Services.Navigation
- {
- using GDNXFD.Alert.Config.Views;
- using Data;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- /// <summary>
- /// implementation of the contract for navigation service.
- /// </summary>
- public class NavigationService : INavigationService
- {
- private Stack<UIElement> backStack = new Stack<UIElement>();
- private UIElement currentElement;
- private MainWindow mainWindow;
- private Grid contentHost;
- /// <summary>
- /// Navigate to the previous content in the stack.
- /// </summary>
- public void NavigateBack()
- {
- this.NavigateBackStack();
- }
- public void NavigateToRuleForm(AlertRule alertRule, FormMode fMode=FormMode.ReadOnly)
- {
- NavigateTo(new RuleForm(alertRule, fMode));
- }
- /// <summary>
- /// Open Travel Request list
- /// </summary>
- public void NavigateToRuleList()
- {
- NavigateTo(new RuleList());
- }
- /// <summary>
- /// Open Travel Request list
- /// </summary>
- public void NavigateToDIList()
- {
- NavigateTo(new DIList());
- }
- /// <summary>
- /// Open Travel Request list
- /// </summary>
- public void NavigateToLogin()
- {
- NavigateTo(new Login());
- }
- /// <summary>
- /// Private Navigate method.
- /// </summary>
- /// <param name="view"></param>
- private void NavigateTo(UIElement view)
- {
- GetContentHost();
- if (this.currentElement == null)
- this.currentElement = this.contentHost.Children.Count > 0 ? this.contentHost.Children[0] : null;
- this.backStack.Push(this.currentElement);
- this.currentElement = null;
- this.currentElement = view;
- this.contentHost.Children.Clear();
- this.contentHost.Children.Add(this.currentElement);
- }
- /// <summary>
- /// Private navigate back method.
- /// </summary>
- private void NavigateBackStack()
- {
- this.contentHost.Children.Clear();
- if (this.backStack.Peek() != null)
- this.currentElement = this.backStack.Pop();
- this.contentHost.Children.Add(this.currentElement);
- }
- /// <summary>
- /// Auxiliar method to obtain the main window.
- /// </summary>
- /// <returns></returns>
- private MainWindow GetMainWindow()
- {
- foreach (Window window in App.Current.Windows)
- {
- if ((window as MainWindow) != null)
- {
- return (window as MainWindow);
- }
- }
- return null;
- }
- private void GetContentHost()
- {
- if (this.mainWindow == null)
- this.mainWindow = GetMainWindow();
- if (this.mainWindow != null && this.contentHost == null)
- this.contentHost = this.mainWindow.PARTContentHost;
- }
- }
- }
|