1

WP支持黑暗和輕的主題。用戶可以將手機上的主題更改爲明亮或黑暗,並且具體屬性也會相應更改,如文本顏色等。自動按鈕圖標支持主題Windows手機

我試圖創建具有圖標圖像的按鈕,以自動更改以支持用戶選擇的主題。

有沒有簡單的方法來做到這一點?

這裏是我做我的當前按鈕的方式:

<Button Name="button" Margin="250,443,86,44" VerticalAlignment="Center" Style="{StaticResource roundButton}" Height="120" Click="button_click" HorizontalAlignment="Center" Width="120"> 
      <Image Source="/Assets/Tiles/picture.png" HorizontalAlignment="Left" VerticalAlignment="Center" /> 
    </Button> 
+0

這是用於appbar,還是在頁面內? – 2014-09-05 12:25:12

+0

對不起,在頁面中。 – AlphaWolf 2014-09-05 12:31:49

+0

你可以展示你的硬性方法嗎? – loop 2014-09-05 14:15:49

回答

1

你可以做這樣的事情。您可以在應用程序運行時檢測設置了哪個主題,並相應地更改UI元素。林在MainPage.xaml中頁面的OnNavigatedTo方法做此更改的元素在MainPage.xaml

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    var theme = (Visibility)Resources["PhoneLightThemeVisibility"]; 

    if (theme == System.Windows.Visibility.Visible) 
    { 
     // Change the UI for Light theme 
    } 
    else 
    { 
     // Change the UI for Dark theme 
    } 
} 

嘗試。這應該適合你。