2012-04-10 31 views
0

我有一個圖像,當用戶按下時,不透明度將淡出,直到數值爲0。但是,只有用戶按住圖像,效果纔會繼續。是否有一種可能的方式來改變代碼:當用戶按下,而不按住,不透明度衰落效果將保持?我希望在XAML中做到這一點。加載故事板的所有效果直到完成

<EventTrigger RoutedEvent="Button.Click" SourceName="press"> 
     <EventTrigger.Actions> 
      <BeginStoryboard Storyboard="{StaticResource showA}"/> 
     </EventTrigger.Actions> 
    </EventTrigger> 

<Button Grid.Column="5" Command="{Binding Path=PressC}" CommandParameter="dot" Style="{StaticResource TransparentButton}"> 
       <Button.Template> 
        <ControlTemplate TargetType="{x:Type Button}"> 
         <Grid> 
          <Image Name="image5" Source="/W;component/Images/t.png" Height="100" /> 
          <Image Name="pressed5" Source="/W;component/Images/T.png" Height="100" Width="200" Margin="-23,-136,-21,0" Visibility="Hidden" /> 
         </Grid> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsPressed" Value="True">   
           <Trigger.EnterActions> 
            <BeginStoryboard> 
             <Storyboard> 
              <DoubleAnimation Storyboard.TargetName="pressed5" Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/> 
             </Storyboard> 
            </BeginStoryboard> 
           </Trigger.EnterActions> 

           <Setter Property="Panel.ZIndex" Value="999"/>       
           <Setter TargetName="pressed5" Property="Visibility" Value="Visible"/>          
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Button.Template> 
      </Button> 

回答

1

可以顯示完整的xaml嗎?由於Image沒有IsPressed屬性,因此不清楚它是如何爲你工作的。如預期的按鍵作品 類似代碼:

<Button Background="Aquamarine"> 
<Button.Style> 
    <Style TargetType="Button"> 
    <Style.Triggers> 
     <Trigger Property="IsPressed" Value="True"> 
     <Trigger.EnterActions> 
      <BeginStoryboard> 
      <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/> 
      </Storyboard> 
      </BeginStoryboard> 
     </Trigger.EnterActions> 
     </Trigger> 
    </Style.Triggers> 
    </Style> 
</Button.Style>  

而對於圖像它EventTrigger工作過:

<Image Source="d:\123.png"> 
<Image.Style> 
    <Style TargetType="Image"> 
    <Style.Triggers> 
     <EventTrigger RoutedEvent="MouseDown">    
      <BeginStoryboard> 
      <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1.5" From="1" To="0"/> 
      </Storyboard> 
      </BeginStoryboard>    
     </EventTrigger> 
    </Style.Triggers> 
    </Style> 
</Image.Style> 

+0

THX @Nikolay,這裏是我的代碼.. – hakunabean 2012-04-10 07:33:38

+0

好了,現在我明白了問題。您按下的圖像只有在按下按鈕時纔可見(''僅在Button.IsPresssed = True時有效)。因此,當用戶停止按下按鈕時,圖像變得不可見,並且您看不到動畫的結果。我會嘗試通過trigget設置Opacity not Visibility,但我不確定要實現哪種效果。 – Nikolay 2012-04-10 07:43:45

+0

Omg如果設置爲<<觸發屬性=「IsPressed」值=「True」>'爲'Value =「False」',它的工作原理! Thx男人。其實我的圖像是這樣工作的:有2個圖像,第二個圖像是隱藏的。當我點擊第一張圖片時,第二張圖片將會出現,並會在幾秒鐘內消失。 – hakunabean 2012-04-10 08:00:25

相關問題