Xaml WinRT:新视图/窗口不继承App.RequestedTheme
是否可以在WinRT或通用windows应用程序中同时使用主题和新窗口 应用程序的RequestedTheme不是由次要视图“继承”的,例如Xaml WinRT:新视图/窗口不继承App.RequestedTheme,xaml,windows-runtime,win-universal-app,Xaml,Windows Runtime,Win Universal App,是否可以在WinRT或通用windows应用程序中同时使用主题和新窗口 应用程序的RequestedTheme不是由次要视图“继承”的,例如 async Task OpenNewWindow() { var currentTheme = App.Current.RequestedTheme; // Set to Dark in the App's constructor int newViewId = -1; await newView.Dispatcher.RunAs
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);
}
(基于的示例代码)我的UWP应用程序使用多视图(窗口)样式,主窗口和子窗口可以使用相同的主题。
这是我的应用程序的代码。该应用程序有一个主窗口-显示线程目录和线程,以及多个图像窗口
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;
}
private异步任务createImagePageAsync(字符串url)
{
ViewLifetimeControl viewControl=null;
等待CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal,()=>
{
var f10url=新的f10url(url);
viewControl=ViewLifetimeControl.CreateForCurrentView();
viewControl.Title=f10url.threadTitle;
Url=Url;
viewControl.StartViewInUse();
var frame=新帧();
frame.RequestedTheme=GetSavedElementTheme();//我可以理解您创建新窗口的代码,但是否要为所有窗口设置一个RequestedTheme
?为此,在UWP应用程序中,您可以在app.xaml文件中定义此属性。谢谢Grace。在应用程序构造函数中设置RequestedTheme属性应与在xaml中设置相同。我需要将其设置为prog从语法上讲,正如在完整代码中一样,它是从用户为应用程序存储的首选项中读取的。