protected virtual void ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var window = _frameworkElementsDictionary.Keys.FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? _frameworkElementsDictionary.Keys.Last(); _frameworkElementsDictionary[window].Push(element); window.Content = element; }
protected override void ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { if (_root is MainWindow && element is MvxWpfView) { var mainWindow = _root as MainWindow; // this is really hacky - do it using attributes isnt mainWindow.PresentInRegion(element, attribute); } }
protected virtual void ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var contentControl = _frameworkElementsDictionary.Keys.FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? _frameworkElementsDictionary.Keys.Last(); if (!attribute.StackNavigation && _frameworkElementsDictionary[contentControl].Any()) { _frameworkElementsDictionary[contentControl].Pop(); // Close previous view } _frameworkElementsDictionary[contentControl].Push(element); contentControl.Content = element; }
protected virtual Task <bool> ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var contentControl = FrameworkElementsDictionary.Keys.FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? FrameworkElementsDictionary.Keys.Last(); if (!attribute.StackNavigation && FrameworkElementsDictionary[contentControl].Any()) { FrameworkElementsDictionary[contentControl].Pop(); // Close previous view } FrameworkElementsDictionary[contentControl].Push(element); contentControl.Content = element; return(Task.FromResult(true)); }
protected virtual void ShowContentViewController( NSViewController viewController, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var window = Windows.FirstOrDefault(w => w.Identifier == attribute.WindowIdentifier) ?? Windows.Last(); if (!string.IsNullOrEmpty(viewController.Title)) { window.Title = viewController.Title; } window.ContentView = viewController.View; window.ContentViewController = viewController; }
public void PresentInRegion(FrameworkElement frameworkElement, MvxContentPresentationAttribute attribute) { switch (attribute.WindowIdentifier) { case "Detail": RightHandColumn.Children.Clear(); RightHandColumn.Children.Add(frameworkElement); break; default: LeftHandColumn.Children.Clear(); LeftHandColumn.Children.Add(frameworkElement); break; } }
protected virtual Task <bool> ShowContentViewController( NSViewController viewController, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var window = FindPresentingWindow(attribute.WindowIdentifier, viewController); if (!string.IsNullOrEmpty(viewController.Title)) { window.Title = viewController.Title; } window.ContentView = viewController.View; window.ContentViewController = viewController; return(Task.FromResult(true)); }
protected override Task <bool> ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { var contentControl = FrameworkElementsDictionary.Keys.FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? FrameworkElementsDictionary.Keys.Last(); if (!attribute.StackNavigation && FrameworkElementsDictionary[contentControl].Any()) { FrameworkElementsDictionary[contentControl].Pop(); // Close previous view } var containerView = FindChild <Frame>(contentControl, navFrameName) as ContentControl; if (containerView != null) { if (FrameworkElementsDictionary.ContainsKey(containerView) == false) { FrameworkElementsDictionary.Add(containerView, new Stack <FrameworkElement>()); } FrameworkElementsDictionary[containerView].Push(element); containerView.Content = element; return(Task.FromResult(true)); } return(base.ShowContentView(element, attribute, request)); }
protected override Task <bool> ShowContentView( FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { if (!(attribute is CustomMvxContentPresentationAttribute customAttribute)) { return(base.ShowContentView(element, attribute, request)); } var contentControl = FrameworkElementsDictionary.Keys .FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? FrameworkElementsDictionary.Keys.Last(); if (!customAttribute.NoHistory && !attribute.StackNavigation && FrameworkElementsDictionary[contentControl].Any()) { FrameworkElementsDictionary[contentControl].Pop(); // Close previous view } //We can't use a frame because we wouldn't be able to access the parents data //that's why we use a content control if (WindowsUtils.GetDescendantFromName(contentControl, customAttribute.ContentFrame) is ContentControl control) { control.Content = element; } else { contentControl.Content = element; } if (customAttribute.NoHistory) { return(Task.FromResult(true)); } FrameworkElementsDictionary[contentControl].Push(element); return(Task.FromResult(true)); }
/// <summary> /// This gets called when navigation to view model happens. /// Depending on what the type is, will define where the class goes. /// Either to MesDocumentManager or main view if not a IMesDocument or IMesTool /// </summary> /// <param name="element"></param> /// <param name="attribute"></param> /// <param name="request"></param> /// <returns></returns> protected override async Task <Boolean> ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request) { try { // Everything that passes here should be a view IMvxView view = element as IMvxView; IMesDocumentManager manager = Mvx.IoCProvider.Resolve <IMesDocumentManager>(); // from which we can now get the view model. switch (view.ViewModel) { case IMesDocument document: // Try to set view, this is needed for DocumentManager IMesDocument docViewModel = (IMesDocument)view.ViewModel; docViewModel.View = view; // Needed for Binding with AvalonDock // Add to manager model manager.Documents.Add(docViewModel); _log?.LogTrace($"Add {document} to IMesDocumentManager.Documents"); return(true); case IMesTool tool: // Try to set view, this is needed for DocumentManager IMesTool toolViewModel = (IMesTool)view.ViewModel; toolViewModel.View = view; // Needed for Binding with AvalonDock // Add to manager model manager.Tools.Add(toolViewModel); _log?.LogTrace($"Add {tool} to IDocumentManager.Tools"); return(true); default: _log?.LogTrace($"Passing to parent {view.ViewModel.ToString()}"); return(await base.ShowContentView(element, attribute, request)); } } catch (Exception exception) { _log?.LogError(exception, $"Error seen during navigation request to {request.ViewModelType.Name} - error {exception.ToLongString()}"); throw; } }