2011-06-06 39 views
2

所以我在我的MainPage上顯示的列表中有幾個項目。我有一個按鈕,看起來像這樣:我怎樣才能停止Windows Phone中的按鈕控制從單擊時發出難看的白色閃光?

<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> 

每次我點擊它,圖像消失在這個明亮的白色矩形下。我寧願讓它顯示另一張圖片。我怎樣才能做到這一點?

感謝您的期待

+0

可能重複的[Silverlight的/ WP7:編程改變按鈕的背景圖像(http://stackoverflow.com/questions/3797304/silverlight-wp7-programmatically-change-the-button-background-image) – 2011-06-06 09:55:44

+0

這不醜! – ColinE 2011-06-06 09:56:15

+0

嘗試一個隱形按鈕: http://stackoverflow.com/a/13366713/1821686 – YarsRevenge13 2012-11-13 18:49:24

回答

1
+0

感謝您的鏈接。 silvergeek示例正是我一直在尋找的:) – Freakishly 2011-06-06 10:04:27

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> 

注意PressedVisualState如何改變ButtonBackground元素的背景(即Border)到PhoneForegroundBrush 。這是什麼讓你的按鈕變成白色。

您可以創建自己的按鈕模板,更改Pressed狀態下的圖像。如果您不確定如何創建自己的控件模板,請搜索網站。

0

這個問題是一歲。然而,這是實現你想要的完美方式。當你按下appbar圖標時,我發現你想模擬類似的體驗。

Coding4fun工具包有你需要的確切疾病。

下面是代碼會是什麼樣子,

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

enter image description here

Ofcourse,你就必須包括coding4fun庫到您的項目。將此行添加到頁面的頂部。

xmlns:c4fControls="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls" 
相關問題