原創|其它|編輯:郝浩|2012-12-11 15:58:19.000|閱讀 434 次
概述:在ComponentOne的最新2012 v3版本中,C1Chart提供了新的動畫API,讓在圖表中加入動畫元素變得更加簡單。接下來就為大家介紹以下如何使用XAML創建圖表動畫。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在ComponentOne的最新2012 v3版本中,C1Chart控件的功能有了很大的增強,動畫功能便是其中之一,C1Chart提供了新的動畫API,讓在圖表中加入動畫元素變得更加簡單。接下來就為大家介紹以下如何使用XAML創建圖表動畫。
C1Chart中有一個單PlotElementAnimation類,它只有兩個屬性:Storyboard和SymbolStyle。這兩個屬性讓你可能靈活將動畫故事板和風格的任意組合來自定義動畫。然后在圖表數據對象中將PlotElementAnimation綁定至一個新LoadAnimation屬性,并可以完成圖表動畫的創建。
以下是一個通過改變透明度來實現圖表淡入加載效果的代碼,通過創建PlotElementAnimation的Storyboard和SymbolStyle屬性便可完成。
<c1:C1Chart x:Name="c1Chart1" Palette="Office"> <c1:C1Chart.Data> <c1:ChartData> <c1:DataSeries Label="s1" Values="1 2 3 4 5" /> <c1:ChartData.LoadAnimation> <c1:PlotElementAnimation Storyboard="{StaticResource sbOpacity}" SymbolStyle="{StaticResource styleOpacity}"/> </c1:ChartData.LoadAnimation> </c1:ChartData> </c1:C1Chart.Data> </c1:C1Chart>
接下來創建資源
<Style TargetType="c1:PlotElement" x:Key="styleOpacity"> <Setter Property="Opacity" Value="0" /> </Style> <Storyboard x:Key="sbOpacity"> <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" From="0" To="1" c1:PlotElementAnimation.IndexDelay="0.5"/> </Storyboard>
Storyboard和SymbolStyle都是典型的XAML資源,非常簡單易用,效果如下。
創建縮放動畫,需要用到Style和Storyboard中的另外兩個屬性EasingFunction和RenderTransformOrigin。
<Style TargetType="c1:PlotElement" x:Key="styleScale"> <Setter Property="RenderTransform"> <Setter.Value> <ScaleTransform ScaleX="0" ScaleY="0" /> </Setter.Value> </Setter> <Setter Property="RenderTransformOrigin" Value="0.5, 0.5" /> </Style> <Storyboard x:Key="sbScale"> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).ScaleX" Duration="00:00:01" From="0" To="1" c1:PlotElementAnimation.IndexDelay="0.5"> <DoubleAnimation.EasingFunction> <CubicEase EasingMode="EaseInOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).ScaleY" Duration="00:00:00" From="0" To="1"> <DoubleAnimation.EasingFunction> <CubicEase EasingMode="EaseInOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard>
只需將Scale屬性之一為0,就可以創建以下效果。
使用RotateTransform便可以創建旋轉動畫,還可以自定義原點(RenderTransformOrigin)。
<Style TargetType="c1:PlotElement" x:Key="styleRotate"> <Setter Property="RenderTransform"> <Setter.Value> <RotateTransform Angle="180" /> </Setter.Value> </Setter> <Setter Property="RenderTransformOrigin" Value="0.5, 0.5" /> </Style> <Storyboard x:Key="sbRotate"> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).Angle" Duration="00:00:01" To="1" c1:PlotElementAnimation.IndexDelay="0.5"> <DoubleAnimation.EasingFunction> <BackEase EasingMode="EaseIn" Amplitude="5" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard>
在Style資源中使用TransformGroup,就能夠創建復合動畫了。
<Style TargetType="c1:PlotElement" x:Key="styleComposite"> <Setter Property="RenderTransform"> <Setter.Value> <TransformGroup> <ScaleTransform ScaleX="0" ScaleY="0" /> <RotateTransform Angle="180" /> </TransformGroup> </Setter.Value> </Setter> <Setter Property="RenderTransformOrigin" Value="0.5, 0.5" /> <Setter Property="Opacity" Value="0" /> </Style> <Storyboard x:Key="sbComposite"> <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" From="0" To="1" c1:PlotElementAnimation.IndexDelay="1"/> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].ScaleX" Duration="00:00:01" From="0" To="1" c1:PlotElementAnimation.IndexDelay="1"> <DoubleAnimation.EasingFunction> <CubicEase EasingMode="EaseInOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].ScaleY" Duration="00:00:01" From="0" To="1"> <DoubleAnimation.EasingFunction> <CubicEase EasingMode="EaseInOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].Angle" Duration="00:00:01" To="1" c1:PlotElementAnimation.IndexDelay="1"> <DoubleAnimation.EasingFunction> <BackEase /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網