1

私の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 のデフォルト アイコンを使用します。私の問題は、明るいテーマを変更すると、アイコンが変更されず、白のままになることです。テーマを変更するときにこの画像を変更するにはどうすればよいですか?

4

3 に答える 3

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>

詳細はこちら

于 2012-05-16T08:56:06.490 に答える
0

ボタン イメージの色の自動変換は、AppBar でのみ行われます。他のすべてのイメージについては、自分でテストする必要があります。
このようなものが動作します:

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

次に、そのブール値を使用して、表示する画像を決定できます。各イメージのバージョンごとに標準の命名規則を使用することをお勧めします。これにより、コンバーターでの作業が容易になります。

于 2012-05-16T08:17:27.737 に答える
-1

「白い」アイコンを使用するだけです。Microsoft SDKs\Windows Phone\v7.1\Icons\dark にあります。

于 2012-05-16T06:42:37.083 に答える