是否可以在WinRT或通用 Windows应用程序中一起使用主题和新窗口? 应用程序的RequestedTheme不是由次要视图“继承”,例如…… async Task OpenNewWindow(){ var currentTheme = App.Current.RequestedTheme; //
应用程序的RequestedTheme不是由次要视图“继承”,例如……
async Task OpenNewWindow() { var currentTheme = App.Current.RequestedTheme; // Set to Dark in the App's constructor int newViewId = -1; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Next line shows theme reset to Light and cannot be changed to match the main view's theme var themeForNewView = App.Current.RequestedTheme; // Code omitted here to create the new Frame Window.Current.Content = newFrame; Window.Current.Activate(); var coreWindow = CoreWindow.GetForCurrentThread(); newViewId = ApplicationView.GetApplicationViewIdForWindow(coreWindow); } // Display the new view and window - APPEARS WITH LIGHT THEME, NOT THE THEME SET IN THE ORIGINAL APP CONSTRUCTOR var currentViewId = ApplicationView.GetForCurrentView().Id; var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync( newViewId, ViewSizePreference.UseHalf, currentViewId, ViewSizePreference.UseHalf); }
(示例代码基于https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn582023.aspx)
我的UWP应用程序使用多视图(窗口)样式,主窗口和子窗口可以使用相同的主题.这是我的应用程序 F10 image bbs browser的代码.该应用程序有一个主窗口 – 显示线程目录和线程,以及多个图像窗口.
private async Task<ViewLifetimeControl> createImagePageAsync(string url) { ViewLifetimeControl viewControl = null; await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var f10url = new F10Url(url); viewControl = ViewLifetimeControl.CreateForCurrentView(); viewControl.Title = f10url.threadTitle; viewControl.Url = url; viewControl.StartViewInUse(); var frame = new Frame(); frame.RequestedTheme = GetSavedElementTheme(); // <<------- here RegistTitleBarColor(); frame.Navigate(typeof(ImagePage), viewControl); Window.Current.Content = frame; Window.Current.Activate(); ApplicationView.GetForCurrentView().Title = viewControl.Title; }); ((F10Client)F10Client.Current).SecondaryViews.Add(viewControl); return viewControl; }
是的,只需为新框架设置相同的请求主题即可. GetSavedElementTheme()只返回在应用程序首选项中保存的主题–Windows.UI.Xaml.ElementTheme.Default,Dark或Light.
我希望代码可以帮助你.
注意 – 我的代码基于Microsoft
Multiple views sample.