2012-05-16 65 views
1

Windows Phone的主題在我的XAML代碼我有這個選擇我的形象:如何根據XAML

<Button Grid.ColumnSpan="2" Grid.Row="3" Height="72" Name="btnSend" Click="btnSend_Click"> 
     <Button.Background> 
      <ImageBrush x:Name="imButton" ImageSource="/icons/appbar.feature.email.rest.png" Stretch="None"/> 
     </Button.Background> 
</Button> 

對於ImageSource的我使用SDK的默認圖標,我的問題是,當我改變德主題在光照下,圖標不會改變並保持白色。如何在更改主題時更改此圖像?

回答

1

你可以使用透明來解決這個問題。

首先,創建一個樣式按鈕:

<phone:PhoneApplicationPage.Resources> 
    <Style x:Key="IconButton" TargetType="Button"> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/> 
     <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> 
     <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
     <Setter Property="Padding" Value="10,3,10,5"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="Button"> 
        <Grid Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 

         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}"> 
          <Grid x:Name="ContentContainer" OpacityMask="{TemplateBinding Content}" Background="{TemplateBinding Foreground}"/> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

後使用它如下:

<Button Style="{StaticResource IconButton}" > 
    <ImageBrush ImageSource="/icons/home.png"> 
</Button> 

更多信息試圖找到here

-1

你只需要使用「白色」圖標。您可以在Microsoft SDK \ Windows Phone \ v7.1 \ Icons \ dark中找到它。

+0

這僅適用於'ApplicationBarButton's但他們正在使用一個常規的'Button',所以不在應用欄中。 –

0

僅在AppBar上自動轉換按鈕圖像的顏色。對於所有其他圖形你必須自己做測試。
像這樣將工作:

var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible; 

然後,您可以使用布爾值來決定要顯示的圖像。爲每個圖像的不同版本制定一個標準的命名約定可能是推薦的,這將使得使用轉換器更容易。

+0

非常感謝 – Anthony