C# 通知栏在灯光模式下显示为全白色

C# 通知栏在灯光模式下显示为全白色,c#,uwp,uwp-xaml,windows-10-mobile,template10,C#,Uwp,Uwp Xaml,Windows 10 Mobile,Template10,我使用的是Template 10,在Windows 10 Mobile中,当我选择灯光模式时,通知栏显示为全白色 并且看不到通知、时间等 在黑暗模式下,一切看起来都很好: 如何解决这个问题?正如@mvermef所说,为了解决这个问题,我们可以根据应用程序的主题设置状态栏中使用的颜色。我们可以使用属性获取应用程序的主题,并使用类中的属性设置状态栏的颜色。举个简单的例子: public MainPage() { InitializeComponent(); NavigationC

我使用的是Template 10,在Windows 10 Mobile中,当我选择灯光模式时,通知栏显示为全白色

并且看不到通知、时间等

在黑暗模式下,一切看起来都很好:


如何解决这个问题?

正如@mvermef所说,为了解决这个问题,我们可以根据应用程序的主题设置状态栏中使用的颜色。我们可以使用属性获取应用程序的主题,并使用类中的属性设置状态栏的颜色。举个简单的例子:

public MainPage()
{
    InitializeComponent();
    NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

    if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
    {
        var statusBar = StatusBar.GetForCurrentView();
        if (statusBar != null)
        {
            if (Application.Current.RequestedTheme == ApplicationTheme.Light)
            {
                statusBar.ForegroundColor = Windows.UI.Colors.Black;
            }
            else if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
            {
                statusBar.ForegroundColor = Windows.UI.Colors.White;
            }
        }
    }
}

请注意使用
状态​Bar
类,我们需要在项目中为UWP提供参考Windows Mobile Extensions。

正如@mvermef所说,为了解决这个问题,我们可以根据应用程序的主题设置状态栏中使用的颜色。我们可以使用属性获取应用程序的主题,并使用类中的属性设置状态栏的颜色。举个简单的例子:

public MainPage()
{
    InitializeComponent();
    NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

    if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
    {
        var statusBar = StatusBar.GetForCurrentView();
        if (statusBar != null)
        {
            if (Application.Current.RequestedTheme == ApplicationTheme.Light)
            {
                statusBar.ForegroundColor = Windows.UI.Colors.Black;
            }
            else if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
            {
                statusBar.ForegroundColor = Windows.UI.Colors.White;
            }
        }
    }
}

请注意使用
状态​Bar
类,我们需要在项目中为UWP
提供Windows Mobile扩展的参考。

在数据库设置/迁移完成后,我在我的汉堡包中对
UIElement CreateRootElement()进行重写

 if(Template10.Utils.DeviceUtils.Current().IsPhone()){
   var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
   if(statusBar != null)
   {  
       if(Application.Current.RequestedTheme == ApplicationTheme.Light)
          //background && foreground or combination, and dependent on color choices
          statusBar.ForegroundColor = Windows.UI.Colors.Black;
      else if(Application.Current.RequestedTheme == ApplicationTheme.Dark
          statusBar.ForegroundColor = Windows.UI.Colors.White;
  }
}

Template10已经内置了很多逻辑,只要知道它在哪里就可以了。正如@Jay Zuo所说,您还必须包括移动引用。

在数据库设置/迁移完成后,我在汉堡包中对
UIElement CreateRootElement()
进行覆盖

 if(Template10.Utils.DeviceUtils.Current().IsPhone()){
   var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
   if(statusBar != null)
   {  
       if(Application.Current.RequestedTheme == ApplicationTheme.Light)
          //background && foreground or combination, and dependent on color choices
          statusBar.ForegroundColor = Windows.UI.Colors.Black;
      else if(Application.Current.RequestedTheme == ApplicationTheme.Dark
          statusBar.ForegroundColor = Windows.UI.Colors.White;
  }
}

Template10已经内置了很多逻辑,只要知道它在哪里就可以了。正如@Jay Zuo所说,您还必须包括手机参考。

对,因为您没有发送状态栏的背景色。它不是自动处理的。这个框架没有考虑到这一点,我想永远也不会。因为它可能是一种对比色,也可能是接近默认颜色的色调,所以左上至开发人员右,因为您没有发送状态栏的背景色。它不是自动处理的。这个框架没有考虑到这一点,我想永远也不会。留给开发人员,因为它可以是对比色或接近默认色调非常感谢!这就解决了问题。我只有一个问题,例如:如果应用程序主题是暗的,而我改为亮的主题,它只会在我关闭并打开应用程序时更新状态栏。当我更改应用程序主题时,是否有任何方法更新状态栏?存在一些代码片段,但需要稍微更改基本T10代码以便于更改。不幸的是,当前的GitHub存储库目前还不具备进行分叉和尝试更改的能力,因为该库目前正在进行代码重构。谢谢!另一个问题,这是可能的吗?主题为轻时:
statusBar.BackgroundColor=Colors.Black;statusBar.ForegroundColor=Colors.White你可以这样设置,但它有意义吗?我希望在应用程序的灯光主题中,状态栏的背景为黑色,图标为白色,就像应用程序的主题在黑暗中一样。非常感谢!这就解决了问题。我只有一个问题,例如:如果应用程序主题是暗的,而我改为亮的主题,它只会在我关闭并打开应用程序时更新状态栏。当我更改应用程序主题时,是否有任何方法更新状态栏?存在一些代码片段,但需要稍微更改基本T10代码以便于更改。不幸的是,当前的GitHub存储库目前还不具备进行分叉和尝试更改的能力,因为该库目前正在进行代码重构。谢谢!另一个问题,这是可能的吗?主题为轻时:
statusBar.BackgroundColor=Colors.Black;statusBar.ForegroundColor=Colors.White您可以这样设置,但它有意义吗?我希望在应用程序的浅主题中,状态栏的背景为黑色,图标为白色,就像应用程序的主题处于黑暗中时一样。我将代码放在文件中:app.xaml.cs in public override async Task OnStartAsync(StartKind StartKind,IActivatedEventArgs args). 在您的示例中,MainPage中有此代码。有什么不同吗?@FernandoSousa我在主页上写了一个例子。在
OnStartAsync
中使用它也应该有效。我将代码放在文件中:App.xaml.cs in public override async Task OnStartAsync(StartKind StartKind,IActivatedEventArgs args)。在您的示例中,MainPage中有此代码。有什么不同吗?@FernandoSousa我在主页上写了一个例子。在
OnStartAsync
中使用它也应该有效。