Windows phone 8.1 状态栏主题
Windows phone 8.1 StatusBar Themeing
我正在为 Windows Phone 8.1(运行时应用程序)创建一个应用程序。我到处都在使用 ThemeResource 来动态获取当前的前景和背景画笔。但我面临的一个问题是 StatusBar。我将其颜色设置为 PhoneChromeBrush,它会根据主题再次变化。我看到前景色和背景色只能从后面的代码中设置。
这是代码:
var statusBar = StatusBar.GetForCurrentView();
statusBar.BackgroundColor = (App.Current.Resources["PhoneChromeBrush"] as SolidColorBrush).Color;
statusBar.BackgroundOpacity = 1;
statusBar.ProgressIndicator.ProgressValue = 1;
await statusBar.ShowAsync();
当主题实际改变时,如何改变StatusBar的颜色?有没有我可以听取主题变化的事件?
我实际上通过将相同的代码放在 Window.Current.Activated 事件处理程序而不是 OnLaunched 中来解决这个问题。我以为每次都会调用 OnLaunched,但事实并非如此。
我不确定当主题更改时您可以收听任何事件,但如果您自己更改主题,那么这应该有效:
MainPage.xaml
<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
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;
}
我正在为 Windows Phone 8.1(运行时应用程序)创建一个应用程序。我到处都在使用 ThemeResource 来动态获取当前的前景和背景画笔。但我面临的一个问题是 StatusBar。我将其颜色设置为 PhoneChromeBrush,它会根据主题再次变化。我看到前景色和背景色只能从后面的代码中设置。
这是代码:
var statusBar = StatusBar.GetForCurrentView();
statusBar.BackgroundColor = (App.Current.Resources["PhoneChromeBrush"] as SolidColorBrush).Color;
statusBar.BackgroundOpacity = 1;
statusBar.ProgressIndicator.ProgressValue = 1;
await statusBar.ShowAsync();
当主题实际改变时,如何改变StatusBar的颜色?有没有我可以听取主题变化的事件?
我实际上通过将相同的代码放在 Window.Current.Activated 事件处理程序而不是 OnLaunched 中来解决这个问题。我以为每次都会调用 OnLaunched,但事实并非如此。
我不确定当主题更改时您可以收听任何事件,但如果您自己更改主题,那么这应该有效:
MainPage.xaml
<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
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;
}