2

そのため、MainPage に表示するリストにいくつかの項目があります。次のようなボタンがあります。

<Button Grid.Column="1" Click="Button_Click" BorderThickness="0" Height="40">
     <Button.Background>
           <ImageBrush ImageSource="/WindowsPhonePanoramaApplication2;component/Images/appbar.feature.email.rest.png" Stretch="None" />
     </Button.Background>
</Button>

クリックするたびに、この明るい白い長方形の下に画像が消えます。代わりに別の画像を表示させたいと思います。どうすればこれを達成できますか?

ご覧いただきありがとうございます

4

3 に答える 3

2

ボタン テンプレートを変更する必要があります。テンプレートは、次のファイル内にあります。

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Design\System.Windows.xaml

テンプレートは次のButtonBaseとおりです。

  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ButtonBase">
        <Grid Background="Transparent">
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualState x:Name="Normal"/>
              <VisualState x:Name="MouseOver"/>
              <VisualState x:Name="Pressed">
                <Storyboard>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}" />
                  </ObjectAnimationUsingKeyFrames>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}" />
                  </ObjectAnimationUsingKeyFrames>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="BorderBrush">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}" />
                  </ObjectAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Disabled">
                <Storyboard>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                  </ObjectAnimationUsingKeyFrames>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="BorderBrush">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                  </ObjectAnimationUsingKeyFrames>
                  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                  </ObjectAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
          </VisualStateManager.VisualStateGroups>
          <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}" >
            <ContentControl x:Name="ContentContainer" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Padding="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
          </Border>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>

Pressed VisualStateが要素の背景ButtonBackground(つまりBorder) をに変更する方法に注意してくださいPhoneForegroundBrush。これが、ボタンが白くなる原因です。

Pressedステート内のイメージを変更して、独自のボタン テンプレートを作成できます。独自のコントロール テンプレートの作成方法がわからない場合は、Web を検索してください。

于 2011-06-06T09:51:48.330 に答える
1

これを行うには、クリックしたときに別の視覚的状態を使用するようにボタンを再テンプレート化する必要があります。

次のイメージ ボタン コントロール/代替手段も参照して
ください
。 ://www.silvergeek.net/windows-phone-7/imagebutton-control-for-win-phone-7/
http://blogs.msdn.com/b/priozersk/archive/2010/08/14/creating -wp7-part-1.aspx のラウンド イメージ ボタン

于 2011-06-06T09:55:30.637 に答える
0

この質問は 1 年前のものです。ただし、ここにあなたが望むものを達成するための完璧な方法があります。appbar アイコンを押したときと同様のエクスペリエンスをシミュレートしたいことがわかりました。

Coding4funツールキットには、まさに必要な問題が含まれています。

コードは次のようになります。

<c4fControls:RoundButton Grid.Column="1" Click="Button_Click" 
    ImageSource="/Myapp;component/Images/appbar.img.png"/>

ここに画像の説明を入力

もちろん、coding4fun ライブラリをプロジェクトに含める必要があります。この行をページの上部にも追加します。

xmlns:c4fControls="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"
于 2012-07-11T19:52:02.353 に答える