2014-12-19 24 views
0

我正在開發一個WPF項目。如果Button的isMouseHover爲true,我想在按鈕上刪除突出顯示(如圖中藍色)。我不確定它是否被稱爲高亮。也許這可能是效果,焦點等。我添加BorderBrush是透明的,但它沒有工作。代碼如下:如何在wpf中IsMouseHover爲true時刪除按鈕上的突出顯示

<Image x:Key="LoginImg" Source="..\Images\Login\oturumac.png" 
     Stretch="Fill"/> 
<Image x:Key="LoginImg_RollOver" Source="..\Images\Login\oturumac_rollover.png" 
     Stretch="Fill"/> 

<Style x:Key="LoginButtonStyle" TargetType="{x:Type Button}"> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Content" Value="{DynamicResource LoginImg_RollOver}"/> 
     </Trigger> 
     <Trigger Property="IsMouseOver" Value="False"> 
      <Setter Property="Content" Value="{DynamicResource LoginImg}"/> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

圖片如下。第一張照片時IsMouseOver爲真:

enter image description here

我該如何解決?

按鈕代碼如下:

<Button Background="Transparent" BorderBrush="Transparent" Style="{DynamicResource LoginButtonStyle}" Click="btnLogin_Click" HorizontalAlignment="Center" VerticalAlignment="Top" Width="180" Grid.Column="1" Grid.Row="4" x:Name="btnLogin" TabIndex="2"/> 
+0

我看到了Sheridan提到的問題,但我解決不了問題。因爲我不選擇或點擊按鈕。只有我將鼠標拖放到按鈕上。按鈕周圍是突出顯示。 –

+0

我的歉意......我誤解了你的問題,並沒有意識到它是一個'Button'。我現在已經重新提出了你的問題。你需要顯示你的'Button'的代碼,以便我們能夠確定你做錯了什麼。當你真的只想改變'Background'顏色時,好像你正在改變'Content'屬性? – Sheridan

+0

我只想改變圖像。但按鈕突出顯示。 Background和BorderBrush是透明的 –

回答

2

您需要提供的ButtonControlTemplate擺脫默認的外觀和感覺。您可以用普通的Image控制器替換默認的Button ControlTemplate,並用ControlTemplate Trigger代替Style Trigger。試試這個:

<Button> 
    <Button.Template> 
     <ControlTemplate> 
      <Image Name="Image" Stretch="None" 
Source="pack://application:,,,/AppName;component/Images/Login/oturumac.png" /> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter TargetName="Image" Property="Source" Value=" 
pack://application:,,,/AppName;component/Images/Login/oturumac_rollover.png" /> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 
相關問題