/// <summary> /// Initializes a new instance of <see cref="NavigationFrame"/> /// </summary> public NavigationFrame() { this.BackStack = new List <PageStackEntry>(); this.ForwardStack = new List <PageStackEntry>(); this.Unloaded += NavigationFrame_Unloaded; Application.Current.Activated += Current_Activated; Application.Current.Deactivated += Current_Deactivated; Application.Current.MainWindow.SizeChanged += Current_SizeChanged; Application.Current.MainWindow.Closed += Current_Closed; this.InputBindings.Add(new KeyBinding(new RelayCommand(async() => await this.GoBack(NavigationType.BackButton)), Key.Back, ModifierKeys.None)); this.currentViewOrientation = MonitorInfo.GetCurrentOrientation(); }
/// <summary> /// When overridden in a derived class, returns a <see cref="DataTemplate"/> based on custom logic. /// </summary> /// <param name="item">The data object for which to select the template.</param> /// <param name="container">The data-bound object.</param> /// <returns>Returns a <see cref="DataTemplate"/> or null. The default value is null.</returns> public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item == null) { return(base.SelectTemplate(item, container)); } var defaultDataTemplateKey = "View_" + item.GetType().Name; var specializedDataTemplateKey = defaultDataTemplateKey; if (Application.Current.Resources.Contains(specializedDataTemplateKey)) { return(Application.Current.Resources[specializedDataTemplateKey] as DataTemplate); } specializedDataTemplateKey = defaultDataTemplateKey; var orientation = MonitorInfo.GetCurrentOrientation(); if (orientation == ViewOrientation.Landscape) { specializedDataTemplateKey += "_Landscape"; } else if (orientation == ViewOrientation.Portrait) { specializedDataTemplateKey += "_Portrait"; } // Example: x:Key="View_MainViewModel_Landscape" if (Application.Current.Resources.Contains(specializedDataTemplateKey)) { return(Application.Current.Resources[specializedDataTemplateKey] as DataTemplate); } if (Application.Current.Resources.Contains(defaultDataTemplateKey)) { return(Application.Current.Resources[defaultDataTemplateKey] as DataTemplate); } return(base.SelectTemplate(item, container)); }