/// <summary> /// Shows the prompt. /// </summary> /// <returns> /// An instance of Task /// </returns> public async Task ShowPrompt() { await Task.Delay(this.PromptOriginsEntity.PromptOriginsIdentity * 1000); this.PromptWindow = ObjectFactory.GetInstance <IPromptWindowViewModel>().Window as ModernWindow; this.PromptWindow.Title = string.Concat("Control ", this.PromptOriginsEntity.PromptOriginsIdentity); this.PromptWindow.Tag = this.PromptOriginsEntity.PromptOriginsIdentity; this.PromptWindow.Owner = Application.Current.MainWindow; // Store Window object in PromptWindowsCollection this.PWPMainViewModel.PromptWindowsCollection.Add(this.PromptWindow); this.PromptWindow.Show(); // inorder to retrieve the ModernFrame the ModernWindow is to be shown first ModernFrame frameContent = (ModernFrame)this.PromptWindow.Template.FindName("ContentFrame", this.PromptWindow); UserControl userControl = new UserControl { Content = GetView <IPromptViewModel>(), Tag = this.PromptOriginsEntity.PromptOriginsIdentity }; frameContent.Content = userControl; this.PWPMainViewModel.PromptsCollection.Add(userControl); IPromptViewModel promptViewModel = (IPromptViewModel)((IView)userControl.Content).DataContext; promptViewModel.PromptEntity.Identity = this.PromptOriginsEntity.PromptOriginsIdentity; }
public NavigationService() { _panelsArray = Tuple.Create(new[] { new Uri("/Pages/NotePanels/NotePanel3.xaml", UriKind.Relative) } , new[] { new Uri("/Pages/OptionsPanels/SettingLayout.xaml", UriKind.Relative) } , new[] { new Uri("/Pages/AuthenticateView.xaml", UriKind.Relative) } , new[] { new Uri("/Pages/AddNotePanel.xaml", UriKind.Relative) } ); _frame = Application.Current.MainWindow.FindChild <ModernFrame>("ModernFrame"); _messenger = Messenger.Default; _messenger.Register <IMainWindow>(this, messenger => { if (messenger.LoadedForm) { _frame = Application.Current.MainWindow.FindChild <ModernFrame>("ModernFrame"); } }); _view = CollectionViewSource.GetDefaultView(_panelsArray.Item1) as CollectionView; }
/// <summary> /// Checks if navigation can be performed to the link /// </summary> /// <param name="target">The target frame, can be null</param> /// <param name="uri">Used when the link is a command</param> /// <returns></returns> public virtual bool CanNavigate(ModernFrame target, Uri uri) { if (uri == null) { return(false); } ICommand command; if (this.commands != null && this.commands.TryGetValue(uri, out command)) { // note: not executed within BBCodeBlock context, Hyperlink instance has Command and CommandParameter set return(command.CanExecute(uri)); } if (uri.IsAbsoluteUri && this.externalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { return(true); } if (target == null) { return(false); } var canNavigate = !Equals(target.CurrentSource, uri); return(canNavigate); }
public void SetUp() { this.contentLoaderMock = new Mock<IContentLoader>(MockBehavior.Strict); this.contentLoaderMock.Setup(x => x.LoadContentAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>())) .Returns((Uri u, CancellationToken t) => Task.FromResult((object)u)); this.parent = new ModernFrame { ContentLoader = this.contentLoaderMock.Object }; }
protected virtual bool SelectedLinkNeedsUpdate(INavigator navigator, ModernFrame frame) { var selectedLink = navigator.SelectedLink; if (selectedLink == null) { var navigatorHasCandidateLinks = navigator.Links.Any(l => l.Source.IsResourceUri()); return(navigatorHasCandidateLinks); } if (frame == null || frame.CurrentSource == null) { return(false); } if (navigator is ModernMenu) { // Debugger.Break(); } if (selectedLink.Source != null) { if (Equals(frame.CurrentSource, selectedLink.Source)) { return(false); } if (navigator.Links.Any(l => Equals(l.Source, frame.CurrentSource))) { return(true); } } return(false); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); Frame = GetTemplateChild("ContentFrame") as ModernFrame; Debug.WriteLine("FRAME: {0}", Frame); // Frame.Navigating += (sender,e) => { if (e.Frame. }; }
public void CanNavigate(string uri, UriKind kind, bool expected) { var navigator = new DefaultLinkNavigator(); var navigateTo = new Uri(uri, kind); var frame = new ModernFrame(); Assert.AreEqual(expected, navigator.CanNavigate(frame, navigateTo)); }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes call System.Windows.FrameworkElement.ApplyTemplate(). /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); ModernFrame frame = (ModernFrame)this.Template.FindName("ContentFrame", this); frame.Navigated += OnNavigated; // critical to make navigation work frame.KeepContentAlive = false; }
internal static void OnFragmentNavigation(ModernFrame sender, FragmentNavigationEventArgs e) { var handler = FragmentNavigation; if (handler != null) { handler(sender, e); } // Debug.WriteLine("FragmentNavigation: fragment:{0}", e.Fragment); }
internal static void OnNavigated(ModernFrame sender, NavigationEventArgs e) { var handler = Navigated; if (handler != null) { handler(sender, e); } // Debug.WriteLine("Navigated: type: {0} source: {1}", e.NavigationType,e.Source); }
internal static void OnNavigationFailed(ModernFrame sender, NavigationFailedEventArgs e) { var handler = NavigationFailed; if (handler != null) { handler(sender, e); } // Debug.WriteLine("NavigationFailed: source:{0} error: {1}", e.Source, e.Error.Message); }
internal static void OnNavigating(ModernFrame sender, NavigatingCancelEventArgs e) { var handler = Navigating; if (handler != null) { handler(sender, e); } // Debug.WriteLine("Navigating: type: {0} source:{1} isParentFrameNavigating: {2}", e.NavigationType, e.Source, e.IsParentFrameNavigating); }
/// <summary> /// Finds the frame identified with given name in the specified context. /// </summary> /// <param name="name">The frame name.</param> /// <param name="context">The framework element providing the context for finding a frame.</param> /// <returns>The frame or null if the frame could not be found.</returns> public static ModernFrame FindFrame(string name, FrameworkElement context) { if (context == null) { throw new ArgumentNullException("context"); } else if (context is ModernWindow) { context = ((ModernWindow)context).ContentFrame; } // collect all ancestor frames ModernFrame[] frames = context.AncestorsAndSelf().OfType <ModernFrame>().ToArray(); if (name == null || name == FrameSelf) { // find first ancestor frame return(frames.FirstOrDefault()); } if (name == FrameParent) { // find parent frame return(frames.Skip(1).FirstOrDefault()); } if (name == FrameTop) { // find top-most frame return(frames.LastOrDefault()); } // find ancestor frame having a name matching the target ModernFrame frame = frames.FirstOrDefault(f => f.Name == name); if (frame == null) { // find frame in context scope frame = context.FindName(name) as ModernFrame; if (frame == null) { // find frame in scope of ancestor frame content ModernFrame parent = frames.FirstOrDefault(); if (parent != null && parent.Content != null) { FrameworkElement content = parent.Content as FrameworkElement; if (content != null) { frame = content.FindName(name) as ModernFrame; } } } } return(frame); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); this.contentFrame = this.Template.FindName("ContentFrame", this) as ModernFrame; if (this.contentFrame != null) { this.contentFrame.Navigated += ContentFrame_Navigated; } }
public FrameNavigationConductor(IViewAware modernWindowViewModel) { // Find the frame by looking in the control template of the window _frame = FindFrame(modernWindowViewModel); if (_frame != null) { // Wire up the events _frame.FragmentNavigation += frame_FragmentNavigation; _frame.Navigated += frame_Navigated; _frame.Navigating += frame_Navigating; } }
#pragma warning disable S3776 // Cognitive Complexity of methods should not be too high /// <summary> /// Finds the frame identified with given name in the specified context. /// </summary> /// <param name="name">The frame name.</param> /// <param name="context">The framework element providing the context for finding a frame.</param> /// <returns>The frame or null if the frame could not be found.</returns> public static ModernFrame FindFrame(string name, FrameworkElement context) #pragma warning restore S3776 // Cognitive Complexity of methods should not be too high { if (context == null) { throw new ArgumentNullException(nameof(context)); } // collect all ancestor frames ModernFrame[] frames = context.AncestorsAndSelf().OfType <ModernFrame>().ToArray(); if (name == null || name == FrameSelf) { // find first ancestor frame return(frames.FirstOrDefault()); } if (name == FrameParent) { // find parent frame return(frames.Skip(1).FirstOrDefault()); } if (name == FrameTop) { // find top-most frame return(frames.LastOrDefault()); } // find ancestor frame having a name matching the target ModernFrame frame = frames.FirstOrDefault(f => f.Name == name); if (frame == null) { // find frame in context scope frame = context.FindName(name) as ModernFrame; if (frame == null) { // find frame in scope of ancestor frame content ModernFrame parent = frames.FirstOrDefault(); if (parent != null && parent.Content != null) { FrameworkElement content = parent.Content as FrameworkElement; if (content != null) { frame = content.FindName(name) as ModernFrame; } } } } return(frame); }
public void ParentNavigationNotifiesChildCancelNavigation() { this.parent.CurrentSource = new Uri("/ParentContent/1.xaml", UriKind.Relative); var childContent = new Mock<ICancelNavigation>(MockBehavior.Strict); childContent.Setup(x => x.OnNavigatingFrom(It.IsAny<NavigatingCancelEventArgs>())); var child = new ModernFrame { Content = childContent.Object, ContentLoader = this.contentLoaderMock.Object }; this.parent.Content = child; this.parent.AddVisualChild(child); this.parent.CurrentSource = new Uri("/ParentContent/2.xaml", UriKind.Relative); childContent.Verify(x => x.OnNavigatingFrom(It.IsAny<NavigatingCancelEventArgs>()), Times.Once); }
/// <summary> /// Performs navigation to specified link. /// </summary> /// <param name="uri">The uri to navigate to.</param> /// <param name="source">The source element that triggers the navigation. Required for frame navigation.</param> /// <param name="parameter">An optional command parameter or navigation target.</param> public virtual void Navigate(Uri uri, FrameworkElement source = null, string parameter = null) { if (uri == null) { throw new ArgumentNullException("uri"); } // first check if uri refers to a command ICommand command; if (Commands != null && Commands.TryGetValue(uri, out command)) { // note: not executed within BBCodeBlock context, Hyperlink instance has Command and CommandParameter set if (command.CanExecute(parameter)) { command.Execute(parameter); } } else if (uri.IsAbsoluteUri && ExternalSchemes != null && ExternalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { // uri is external, load in default browser Process.Start(uri.AbsoluteUri); } else { // perform frame navigation if (source == null) { // source required throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.NavigationFailedSourceNotSpecified, uri)); } // use optional parameter as navigation target to identify target frame (_self, _parent, _top or named target frame) ModernFrame frame = NavigationHelper.FindFrame(parameter, source); if (frame == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.NavigationFailedFrameNotFound, uri, parameter)); } // delegate navigation to the frame frame.Source = uri; } }
public void ParentNavigationChildNotifies() { this.parent.CurrentSource = new Uri(@"/ParentContent/1.xaml", UriKind.Relative); var child = new ModernFrame { CurrentSource = new Uri(@"/ChildContent/1.xaml", UriKind.Relative), ContentLoader = this.contentLoaderMock.Object, }; this.parent.Content = child; this.parent.AddVisualChild(child); var localNavigatings = new List <NavigatingCancelEventArgs>(); var globalNavigatings = new List <NavigatingCancelEventArgs>(); child.Navigating += (_, e) => localNavigatings.Add(e); NavigationEvents.Navigating += (_, e) => globalNavigatings.Add(e); var localNavigations = new List <NavigationEventArgs>(); var globalNavigations = new List <NavigationEventArgs>(); child.Navigated += (_, e) => localNavigations.Add(e); NavigationEvents.Navigated += (_, e) => globalNavigations.Add(e); this.parent.CurrentSource = new Uri(@"/ParentContent/2.xaml", UriKind.Relative); var navigatings = new[] { localNavigatings.Single(), globalNavigatings.Single(x => x.IsParentFrameNavigating) }; foreach (var args in navigatings) { Assert.IsNull(args.Source); Assert.AreEqual(NavigationType.Parent, args.NavigationType); Assert.AreSame(child, args.Frame); Assert.IsTrue(args.IsParentFrameNavigating); } var navigatinons = new[] { localNavigations.Single(), globalNavigations.Single(x => x.NavigationType == NavigationType.Parent) }; foreach (var args in navigatinons) { Assert.IsNull(args.Source); Assert.AreEqual(NavigationType.Parent, args.NavigationType); Assert.AreSame(child, args.Frame); } }
private void Common_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var vm = this.DataContext as LayoutViewModel; if (vm == null) { return; } Console.SetOut(_writer = Cns.Writer); _innerTarget = NavigationHelper.FindFrame("ContentFrame", this); vm.NavigationProvider.GoAction = delegate(NavigationEndpoint endpoint, UserContext context) { NavigationCommands.GoToPage.Execute(endpoint.Destination, _innerTarget); _innerTarget.DataContext = new LiveChartOhclDesignViewModel(); }; }
public void SetUp() { this.link1 = new Link { DisplayName = "1", Source = new Uri("/1", UriKind.RelativeOrAbsolute), LinkNavigator = null }; this.link2 = new Link { DisplayName = "2", Source = new Uri("/2", UriKind.RelativeOrAbsolute) }; this.contentLoaderMock = new Mock <IContentLoader>(); this.frame = new ModernFrame { ContentLoader = this.contentLoaderMock.Object }; this.linkMock = new Mock <ILink>(MockBehavior.Strict); this.navigatorMock = new Mock <INavigator>(MockBehavior.Strict); this.navigatorMock.Setup(x => x.NavigationTarget) .Returns(this.frame); this.linkNavigator = new DefaultLinkNavigator(); }
public void ChildCancelNavigation() { var source = new Uri(@"/ParentContent/1.xaml", UriKind.Relative); this.parent.CurrentSource = source; this.parent.Navigating += (_, e) => e.Cancel = true; var toUri = new Uri(@"/ParentContent/2.xaml", UriKind.Relative); var child = new ModernFrame { CurrentSource = new Uri(@"/ChildContent/1.xaml", UriKind.Relative), ContentLoader = this.contentLoaderMock.Object }; this.parent.Content = child; this.parent.AddVisualChild(child); child.Navigating += (_, e) => e.Cancel = true; this.parent.CurrentSource = toUri; this.contentLoaderMock.Verify(x => x.LoadContentAsync(toUri, It.IsAny<CancellationToken>()), Times.Never); Assert.AreEqual(child, this.parent.Content); // The mock is wired up to return the Uri }
public void AddThenGet(string addUriString, string getUriString, bool expected) { var frame = new ModernFrame { KeepContentAlive = true }; var contentCache = new ContentCache(); var addUri = new Uri(addUriString, UriKind.RelativeOrAbsolute); contentCache.AddOrUpdate(addUri, 1); object value; var getUri = new Uri(getUriString, UriKind.RelativeOrAbsolute); Assert.AreEqual(expected, contentCache.TryGetValue(getUri, out value)); if (expected) { Assert.AreEqual(1, value); } else { Assert.IsNull(value); } }
public SemesterAverage() { InitializeComponent(); ResetViewModel(); Frame = this.frame; viewModel = new Cwa_EngineViewModel(); foreach (var item in CrudOperations.ProgramDictionary.Keys) { cboProgram.Items.Add(CrudOperations.ProgramDictionary[item]); } foreach (var item in CrudOperations.LevelDictionary.Keys) { cboLevel.Items.Add(CrudOperations.LevelDictionary[item]); } foreach (var item in CrudOperations.SemesterDictionary.Keys) { cboSemester.Items.Add(CrudOperations.SemesterDictionary[item]); } }
/// <summary> /// Performs navigation to specified link. /// </summary> /// <param name="target">The target frame, can be null</param> /// <param name="uri">Used when the link is a command</param> public virtual void Navigate(ModernFrame target, Uri uri) { if (uri == null) { return; } // first check if uri refers to a command ICommand command; if (this.commands != null && this.commands.TryGetValue(uri, out command)) { // note: not executed within BBCodeBlock context, Hyperlink instance has Command and CommandParameter set if (command.CanExecute(uri)) { command.Execute(uri); } else { // do nothing } return; } if (uri.IsAbsoluteUri && this.externalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { // uri is external, load in default browser Process.Start(uri.AbsoluteUri); return; } if (target == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.NavigationFailedSourceNotSpecified, uri)); } // delegate navigation to the frame target.CurrentSource = uri; }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes call System.Windows.FrameworkElement.ApplyTemplate(). /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.currentModernFrame = (ModernFrame)this.GetTemplateChild("ContentFrame"); }
/// <summary> /// Initializes a new instance of the <see cref="NavigationFailedEventArgs"/> class. /// </summary> /// <param name="frame"></param> /// <param name="source"></param> /// <param name="error"></param> public NavigationFailedEventArgs(ModernFrame frame, Uri source, Exception error) : base(frame, source) { this.Error = error; }
public static void AddVisualChild(this ModernFrame frame, Visual child) { addVisualChildMethod.Invoke(frame, new object[] { child }); }
/// <summary> /// Initializes a new instance of the <see cref="NavigatingCancelEventArgs"/> class. /// </summary> /// <param name="frame"></param> /// <param name="source"></param> /// <param name="isParentFrameNavigating"></param> /// <param name="navigationType"></param> public NavigatingCancelEventArgs(ModernFrame frame, Uri source, bool isParentFrameNavigating, NavigationType navigationType) : base(frame, source) { this.IsParentFrameNavigating = isParentFrameNavigating; this.NavigationType = navigationType; }
/// <summary> /// /// </summary> /// <param name="frame"></param> /// <param name="source"></param> protected NavigationBaseEventArgs(ModernFrame frame, Uri source) { this.Frame = frame; this.Source = source; }