2013-03-14 63 views
1

我正在開發win8手機項目 每當我點擊一個按鈕時,按鈕背景變爲手機的重音顏色或文本框邊框顏色變爲手機的重音顏色或鍵盤按鈕的顏色 更改爲電話重音顏色... 我試圖覆蓋PhoneAccentBrush在application.resources < solidColorBrush x:Key="PhoneAccentBrush" color="white" />,但它沒有工作 有沒有辦法改變我的應用程序中的所有元素的電話口音顏色?windows phone 8 xaml設置點擊按鈕的顏色

回答

5

您可以更改應用中所有按鈕控件的默認樣式,使其不會在Pressed狀態下使用{StaticResource PhoneAccentBrush}

打開Blend並創建一個簡單的WP8項目,在其中放入一個Button,然後抓取該模板的副本(右鍵單擊該按鈕並編輯副本)。見Jeff Wilcox's blog for a step-by-step description of the process

然後,您可以將模板粘貼到App.xaml。如果您刪除x:Key它將成爲該控件的默認樣式。

或者你可以檢查this StackOverflow question about overriding the theme everywhere

0
private void btnSignIn_Click(object sender, RoutedEventArgs e) 
    { 
     btnSignIn.Background = GetColorFromHexa("#59BD56"); 
    } 
    public SolidColorBrush GetColorFromHexa(string hexaColor) 
    { 
     byte R = Convert.ToByte(hexaColor.Substring(1, 2), 16); 
     byte G = Convert.ToByte(hexaColor.Substring(3, 2), 16); 
     byte B = Convert.ToByte(hexaColor.Substring(5, 2), 16); 
     SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(0xFF, R, G, B)); 
     return scb; 
    } 
3

而不復制整體風格與交融,你可以簡單地覆蓋默認的主題:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.ThemeDictionaries> 
      <ResourceDictionary x:Key="Default"> 
       <!-- Button pressed color --> 
       <SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="OrangeRed"/> 
      </ResourceDictionary> 
     </ResourceDictionary.ThemeDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

與wp8.1至少測試,反正我發現ButtonPressedBackgroundThemeBrush與交融;)