如何根据xaml中的windows phone主题选择我的图像

时间:2012-05-16 06:05:11

标签: windows-phone-7 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中的默认图标,我的问题是当我在光线下更改de主题时,图标不会改变并保持白色。如何在更改主题时更改此图像?

3 个答案:

答案 0 :(得分: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 :(得分:0)

按钮图像颜色的自动转换仅在AppBar上完成。对于所有其他的iamges,你必须自己做测试 这样的事情会起作用:

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

然后,您可以使用该布尔值来确定要显示的图像。建议对每个图像的不同版本使用标准命名约定,这样可以更轻松地使用转换器。

答案 2 :(得分:-1)

你只需要使用&#34; white&#34;图标。您可以在Microsoft SDK \ Windows Phone \ v7.1 \ Icons \ dark

中找到它
相关问题