Writing a WPF application often requires communicating with Server. When the WPF application requires to contact with server, we would like to show a neat animation on the UI like Internet explorer.
This listing shows a way to create an userControl which can be used in applications like
- <window <brbr="">.....
- xmlns:WA="clr-namespace:WaitingAnimated" .... />
- <wa:frontendwaiting width="25" height="25" x:name="animatedIcon" <brbr=""> Margin="200, 50, 300, 300"/>
- </wa:frontendwaiting></window>
In the source code attached I have a toggle button which starts/stops the animation by setting the value of IsAnimated to true or false...
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- animatedIcon.IsAnimated = !animatedIcon.IsAnimated;
- }
Going thru XAML in the user control which is not rocket science but still...
The Grid.Resources has a storyboard, the repeat behavior of animation is forever and the storyboard target property is Angle of the path.
- <grid.resources>
- <storyboard x:key="OnLoaded">
- <doubleanimationusingkeyframes <brbr=""> BeginTime="00:00:00"
- Storyboard.Target="{Binding ElementName=path}"
- Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"
- RepeatBehavior="Forever">
- <splinedoublekeyframe keytime="00:00:00.7000000" value="360">
- </splinedoublekeyframe></doubleanimationusingkeyframes>
- </storyboard>
- </grid.resources>
Path is the union of two circles. The important things in path are the rendertransform origin which translates the origin to the corresponding value, i typically define rendertransform and add all children even if i dont use to keep code extensible. Path fill is the color in the circular path which is filled .
- <path stretch="Fill" stroke="#7F505050" <brbr=""> Data="........"
- RenderTransformOrigin="0.5,0.5" x:Name="path">
- <path.rendertransform>
- <transformgroup>
- <scaletransform scalex="1" scaley="1">
- <skewtransform anglex="0" angley="0">
- <rotatetransform angle="0">
- <translatetransform x="0" y="0">
- </translatetransform></rotatetransform></skewtransform></scaletransform></transformgroup>
- </path.rendertransform>
- <path.fill>
- <lineargradientbrush endpoint="50,100" startpoint="50,0" spreadmethod="Pad" mappingmode="Absolute">
- <gradientstop color="#E500FF00" offset="0">
- <gradientstop color="#3F2BBF2B" offset="1">
- <gradientstop color="#9B020C02" offset="0.32">
- <gradientstop color="#FFFFFFFF" offset="0.641">
- </gradientstop></gradientstop></gradientstop></gradientstop></lineargradientbrush>
- </path.fill>
- </path>
Source code here.
No comments:
Post a Comment