2013-07-08 56 views
1

在.NET 3.5我用OuterGlowBitmapEffect鼠標懸停事件和它的工作完美。按鈕造型OuterGlowBitmapEffect - > DropShadowEffect

現在我移動到.NET 4.0,有沒有工作 - 已過時,所以我重寫我的代碼DropShadowEffect。

它的工作原理,但有鼠標和動畫開始之間長時間的延遲 - 500ms左右。有誰知道爲什麼請?或者我做錯了什麼?

風格:

<Style x:Key="Button" TargetType="{x:Type Button}"> 
<Style.Setters> 
    <Setter Property="Effect"> 
     <Setter.Value> 
      <DropShadowEffect ShadowDepth="0" Color="Yellow" BlurRadius="800" RenderingBias="Performance" Opacity="0" /> 
     </Setter.Value> 
    </Setter> 
</Style.Setters> 
<Style.Triggers> 
    <Trigger Property="Button.IsMouseOver" Value="True"> 
     <Trigger.EnterActions> 
      <BeginStoryboard> 
       <Storyboard> 
        <DoubleAnimation Storyboard.TargetProperty="Effect.Opacity" From="0" To="1" By="1" BeginTime="0:0:0" Duration="0:0:0" /> 
        <DoubleAnimation Storyboard.TargetProperty="Effect.Opacity" From="1" To="0" By="1" BeginTime="0:0:1" Duration="0:0:0" /> 
       </Storyboard> 
      </BeginStoryboard> 
     </Trigger.EnterActions> 
    </Trigger> 
</Style.Triggers> 

和按鍵:

<Button Content="B1" Canvas.Left="207" Canvas.Top="321" Height="70" Name="btn1" Style="{StaticResource Button}" Width="380" /> 
+0

你使用「AllowsTransparency =真」在窗口中的任何機會? –

+0

是的,但這不起作用... – Commanche

+0

你的意思是你試圖將它設置爲false,但它沒有加快速度?這是一個已知的問題。 –

回答

1

可以使用BlurRadius屬性的動畫,而不是不透明度。你也可以使用自動翻轉屬性,回到初始狀態:

<DropShadowEffect ShadowDepth="0" Color="Yellow" 
BlurRadius="0" RenderingBias="Performance"/> 

與動漫:

<DoubleAnimation Storyboard.TargetProperty="Effect.BlurRadius" 
From="0" To="100" Duration="0:0:0.2" AutoReverse="True"/> 

,你應該得到的是沒有延遲立即開始類似的效果。

+0

謝謝,這是好多了,上一個完美的按鈕,當多個按鈕太慢......問題是在其他地方,值Effect.BlurRadius不得超過100! – Commanche

+0

你走了,很高興我能幫上忙。 –