首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows 8.1 StatusBar主题

Windows 8.1 StatusBar主题
EN

Stack Overflow用户
提问于 2016-04-24 20:58:29
回答 2查看 29关注 0票数 0

我正在为Windows 8.1 (运行时应用)创建一个应用程序。我使用ThemeResource everywhere动态获取当前前景和背景刷。但我面临的一个问题是StatusBar。我将它的颜色设置为PhoneChromeBrush,它再次根据主题进行更改。我看到,前景颜色和背景色只能从代码后面设置。

这是代码:

代码语言:javascript
复制
var statusBar = StatusBar.GetForCurrentView();
        statusBar.BackgroundColor = (App.Current.Resources["PhoneChromeBrush"] as SolidColorBrush).Color;
        statusBar.BackgroundOpacity = 1;
        statusBar.ProgressIndicator.ProgressValue = 1;
        await statusBar.ShowAsync();

当主题实际发生变化时,如何改变StatusBar的颜色?有什么活动我可以听的主题变化吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-28 16:59:50

我不确定当主题发生变化时,您是否可以收听到任何事件,但是如果您自己正在更改主题,那么这应该是可行的:

MainPage.xaml

代码语言:javascript
复制
    <Button Content="Use Default Theme" Name="useDefaultThemeButton"
            Click="useDefaultThemeButton_Click"/>

    <Button Content="Use Light Theme" Name="useLightThemeButton"
            Click="useLightThemeButton_Click"/>

    <Button Content="Use Dark Theme" Name="useDarkThemeButton"
            Click="useDarkThemeButton_Click"/>

MainPage.xaml.cs

代码语言:javascript
复制
using Windows.UI.ViewManagement;
using Windows.UI;

    // Use Default Theme

    private void useDefaultThemeButton_Click(object sender, RoutedEventArgs e)
    {
        RequestedTheme = ElementTheme.Default;
        StatusBar.GetForCurrentView().ForegroundColor = null;
    }

    // Use Light Theme

    private void useLightThemeButton_Click(object sender, RoutedEventArgs e)
    {
        RequestedTheme = ElementTheme.Light;
        // exact color unknown
        StatusBar.GetForCurrentView().ForegroundColor = Colors.Black;
    }

    // Use Dark Themme

    private void useDarkThemeButton_Click(object sender, RoutedEventArgs e)
    {
        RequestedTheme = ElementTheme.Dark;
        // exact color unknown
        StatusBar.GetForCurrentView().ForegroundColor = Colors.White;
    }
票数 0
EN

Stack Overflow用户

发布于 2016-04-24 21:51:47

实际上,我通过将相同的代码放在Window.Current.Activated事件处理程序中而不是OnLaunched中来修复这个问题。我以为每次都会给OnLaunched打电话,但事实并非如此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36828816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档