WinRT: new view / window does not inherit App.RequestedTheme

Can I use themes and new windows in WinRT or Universal Windows App?

The requested application method is not "inherited" by secondary views, for example ...

async Task OpenNewWindow()
{
    var currentTheme = App.Current.RequestedTheme; // Set to Dark in the App 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 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);
}

(Sample code based on https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn582023.aspx )

+4
source share
1 answer

UWP multi-view (window), . 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 .

0

All Articles