2011-06-06 14 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" 
相关问题