2014-02-13 22 views
0

我有2個觸發事件,都與<Trigger.EnterActions><Trigger.ExitActions>和這些是IsPressedIsMouseOver觸發屬性重新啓動故事板到第一個狀態

當我點擊一個按鈕,它會起到<Trigger Property="IsPressed" Value="True">故事板:

<Trigger Property="IsPressed" Value="True"> 
    <Trigger.EnterActions> 
     <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/> 
    </Trigger.EnterActions> 
    <Trigger.ExitActions> 
     <BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/> 
    </Trigger.ExitActions> 
</Trigger> 

,這是與這個故事板:

<Storyboard x:Key="MouseDownTimeLine" > 
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" > 
     <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1" /> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

<Storyboard x:Key="MouseUpTimeLine"> 
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" > 
     <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

不同的按鈕也鏈接到同一個故事板。當第二個按鈕被點擊時,我想讓它像故事板一樣播放,但第一個按鈕回到正常狀態。這是故事板的這一部分。

<Storyboard x:Key="MouseExitTimeLine"> 
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Normal" Storyboard.TargetProperty="Opacity" > 
      <SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 

     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity" > 
      <SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

當第二個按鈕被點擊我怎麼觸發的第一個按鈕復位到正常

回答

1

也許我錯了這裏,但好像你有單選按鈕的功能烤成按鈕模板。當你點擊一個按鈕時,它會保持「點擊」(或選中狀態),當你點擊另一個按鈕時,它會「釋放」第一個按鈕的點擊。

我會改變模板來RadioButton目標類型和觸發:

<Trigger Property="IsChecked" Value="True"> 
    <Trigger.EnterActions> 
     <BeginStoryboard x:Name="ButtonCheckedStoryboardBegin" 
         Storyboard="{StaticResource MouseDownTimeLine}"/> 
    </Trigger.EnterActions> 
    <Trigger.ExitActions> 
     <StopStoryboard BeginStoryboardName="ButtonCheckedStoryboardBegin"/> 
    </Trigger.ExitActions> 
</Trigger> 

使用StopStoryboard因爲MouseExitTimeLine duratios爲零。如果你確實需要退出動畫時間,使用:

<Trigger Property="IsChecked" Value="True"> 
    <Trigger.EnterActions> 
     <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/> 
    </Trigger.EnterActions> 
    <Trigger.ExitActions> 
     <BeginStoryboard Storyboard="{StaticResource MouseExitTimeLine}"/> 
    </Trigger.ExitActions> 
</Trigger> 

[第二個選項可以用來作爲是 - 零時間,但它是那麼優雅,IMO]

此外,動畫「懸停」在MouseExitTimeLine中是多餘的,可以刪除,因爲MouseDownTimeLine沒有在「懸停」上設置任何內容。

現在,在RadioButton的每個佈局實例中,添加GroupName="<Some string here>"。在任何給定的時間點,只能檢查一個組中的一個單選按鈕。

+0

當我將模板更改爲RadioButton時,出現大量錯誤。 RadioButton ControlTemplate TargetType與模板類型Button不匹配? – Ben

+0

您需要將'Button'的實例更改爲'RadioButton'。 – XAMeLi