2016-04-24 11 views
0

Windows Phone 8.1(ランタイムアプリ)用のアプリを作成しています。現在のフォアグラウンドとバックグラウンドのブラシを動的に拾うためにどこでもThemeResourceを使用しています。しかし、私が直面している1つの問題はStatusBarです。 PhoneChromeBrushに色を設定しています。PhoneChromeBrushはテーマに基づいて変更されます。フォアグラウンドカラーとバックグラウンドカラーは、コードの背後からのみ設定できることがわかります。Windows phone 8.1 StatusBar Themeing

これはコードです:

var statusBar = StatusBar.GetForCurrentView(); 
     statusBar.BackgroundColor = (App.Current.Resources["PhoneChromeBrush"] as SolidColorBrush).Color; 
     statusBar.BackgroundOpacity = 1; 
     statusBar.ProgressIndicator.ProgressValue = 1; 
     await statusBar.ShowAsync(); 

テーマが実際に変化ステータスバーの色を変更する方法は何ですか?テーマの変更を聞くことができるイベントはありますか?

答えて

0

実際には、OnLaunchedではなくWindow.Current.Activatedイベントハンドラに同じコードを挿入することでこれを修正しました。私はOnLaunchedが毎回呼ばれると思ったが、そうではない。

0

私はあなたがたときに、テーマの変更のために耳を傾けることができますが、テーマを自分で変更している場合、これは動作するはず任意のイベントのわからない:

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; 
    } 
関連する問題