前言:對於此操做,我只想說是微軟的神經,仍是個人笨蛋。爲何EventTrigger就不能像Trigger那樣直接設置Property以及Value就對屬性進行操做,而必需要放一個Action,而默認的Action只有三個,其中兩個爲動畫,一個爲播放聲音,我只想說,能夠洗洗睡了。動畫
正題:在EventTriigger中修改屬性的值,怎麼作呢,咱們都知道EventTrigger中只有Action可使用,而Action的操做中咱們也只能使用StoryBoard來操做,難道咱們也要經過動畫修改各類屬性?沒錯,就是這樣,卻不知動畫不只支持Double、Color、Point,它還支持Object哦,待我上例子。spa
<ControlTemplate.Triggers> <EventTrigger RoutedEvent="MouseDoubleClick"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DocumentPageView_2" Storyboard.TargetProperty="(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="00:00:0.1" Value="{x:Static Visibility.Collapsed}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AdornerDecorator1" Storyboard.TargetProperty="(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="00:00:0.1" Value="{x:Static Visibility.Visible}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeftButtonDown"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AdornerDecorator1" Storyboard.TargetProperty="(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="00:00:0.1" Value="{x:Static Visibility.Collapsed}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DocumentPageView_2" Storyboard.TargetProperty="(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="00:00:0.1" Value="{x:Static Visibility.Visible}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate>
在上述代碼中分別在鼠標單擊事件和雙擊事件中隱藏/顯示了元素,是否是很奇怪咱們使用的ObjectAnimationUsingKeyFrames這個東西,他和DoubleAnimationusingKeyFrames等三個動畫是同樣的,只不過它處理的是除上述三種動畫支持的類型以外的類型。好比如今設置的爲Visibility屬性,並不是Double、Color、Point,那麼咱們就可使用這個東東,使用方法同樣,只不過Value地方要特殊處理哦。code
P.S.此方法,我的感受很差,不知道小夥伴們有木有好的方法,有的話記得@我。blog