2011-02-15 81 views
2

時,WPF按鈕閃爍爲白色我剛剛創建了wpf按鈕,當我單擊按鈕時,它會變成白色,如閃爍,並在釋放按鈕時變回原來的顏色。可能是什麼問題呢?我沒有使用任何效果。以下是我的按鈕xaml。請指教。當我點擊

<Button Content="ROM" Height="121" HorizontalAlignment="Left" Margin="91,269,0,0" Name="button1" VerticalAlignment="Top" Width="566" FontSize="48" BorderBrush="#FF3DFF00" BorderThickness="10" Foreground="White"> 
      <Button.BitmapEffect> 
       <DropShadowBitmapEffect ShadowDepth="2" Color="Gray"></DropShadowBitmapEffect> 
      </Button.BitmapEffect> 
      <Button.Background> 
       <RadialGradientBrush> 
        <GradientStop Color="#FF4094D8" Offset="0" /> 
        <GradientStop Color="#FF2B476F" Offset="1" /> 
       </RadialGradientBrush> 
      </Button.Background> 
     </Button> 
+0

我已經發布了我的xaml代碼,但在我的問題中看不到。 – TNA 2011-02-15 08:41:56

+0

您必須將其格式化爲代碼,使用編輯器欄中的按鈕 – 2011-02-15 08:42:22

回答

1

這是缺省ButtonChrome的原因。如果從表達式中提取默認細節

<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> 
     <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/> 
     <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Padding" Value="1"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type Button}"> 
        <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/> 
        </Microsoft_Windows_Themes:ButtonChrome> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsKeyboardFocused" Value="true"> 
          <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/> 
         </Trigger> 
         <Trigger Property="ToggleButton.IsChecked" Value="true"> 
          <Setter Property="RenderPressed" TargetName="Chrome" Value="true"/> 
         </Trigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Foreground" Value="#ADADAD"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

Microsoft_Windows_Themes:ButtonChrome正在設置效果。如果你想刪除或修改效果,你必須創建自己的控制模板或樣式

2

一種方法是在圖像的頂部放置一個透明按鈕,看起來像一個按鈕,然後將按鈕的不透明度值設置爲零。

<Image Name="buttonImage1" Source="../Images/infoButton.png" Grid.Row="1"/> 
<Button Name="infoButton" Tap="infoButton_Tap" Opacity="0.0" BorderBrush="Transparent" Grid.Row="1"/>