Six animation effects of the WPF series of games (1)

Source: Internet
Author: User

Original: The six animated effects of the WPF series of games (1)

This article is mainly for the interface animation effect processing. First, when the interface is turned on or off, it produces a dynamic effect rather than a stiff display or disappearance (for example). Second, when the mouse is placed on the close window icon, so that it appears flashing effect. These effects are implemented through storyboard and EventTrigger.

1. Start with a simple one, to add a flashing effect to the close icon, you first need to include a close window icon in the ScrollViewer.

... ...<ScrollViewerName= "Queryscrollviewer"scrollviewer.verticalscrollbarvisibility= "Visible" > <StackPanelOrientation= "Vertical" ><!--Close the window icon, set to 20x20<ImageSource= "Image/close.png"Name= "Closeimage"Height= " the"Width= " the"Cursor= "Hand"Margin= "5"HorizontalAlignment= "Right" > <Image.tooltip>Close</Image.tooltip> </Image> <GridName= "Querygrid" ></Grid> </StackPanel></ScrollViewer>... ...

2. Add a flashing effect to the window.resources, which doubleanimation for the width of the closeimage and is in a repeating state. This ensures that the mouse is always flashing when it is on it.

<window.resources> <Storyboardx:Key= "Flashcloseimage" > <DoubleAnimationStoryboard.TargetName= "Closeimage"
Storyboard.TargetProperty= "Width" to= " the"Duration= "0:0:0.8"
RepeatBehavior= "Forever" ></DoubleAnimation> </Storyboard>
... ...</window.resources>

3. The effect is added, and then it is necessary to increase the active event (EventTrigger), one is the mouse (MouseEnter) Start flashing, the other is the mouse left (MouseLeave) stop. Also, because this icon controls the window closing effect, add a click (MouseLeftButtonDown) event to it (the event will continue to be discussed later).

<window.triggers><!--start flashing, and you want to call x:key= "Flashcloseimage" in Window.Resources<EventTriggerSourceName= "Closeimage"RoutedEvent= "Image.mouseenter" > <BeginStoryboardName= "Closeimagebeginstoryboard"
Storyboard="{StaticResourceFlashcloseimage} ">
</BeginStoryboard> </EventTrigger><!--stop flashing, its object is the top Closeimagebeginstoryboard --<EventTriggerSourceName= "Closeimage"RoutedEvent= "Image.mouseleave" > <StopstoryboardBeginstoryboardname= "Closeimagebeginstoryboard" >
</Stopstoryboard> </EventTrigger><!--Close window events, later<EventTriggerSourceName= "Closeimage"RoutedEvent= "Image.mouseleftbuttondown" > <BeginStoryboardName= "Closequerycanvasstoryboard"
Storyboard="{StaticResourceClosequerycanvas} ">
</BeginStoryboard> </EventTrigger>
... ... </window.triggers>

4. All animation effects and events are added, so you can see the effects:

Cond......

Six animation effects of the WPF series of games (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.