原創(chuàng)|其它|編輯:郝浩|2012-12-11 15:58:19.000|閱讀 434 次
概述:在ComponentOne的最新2012 v3版本中,C1Chart提供了新的動(dòng)畫API,讓在圖表中加入動(dòng)畫元素變得更加簡(jiǎn)單。接下來(lái)就為大家介紹以下如何使用XAML創(chuàng)建圖表動(dòng)畫。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在ComponentOne的最新2012 v3版本中,C1Chart控件的功能有了很大的增強(qiáng),動(dòng)畫功能便是其中之一,C1Chart提供了新的動(dòng)畫API,讓在圖表中加入動(dòng)畫元素變得更加簡(jiǎn)單。接下來(lái)就為大家介紹以下如何使用XAML創(chuàng)建圖表動(dòng)畫。
C1Chart中有一個(gè)單PlotElementAnimation類,它只有兩個(gè)屬性:Storyboard和SymbolStyle。這兩個(gè)屬性讓你可能靈活將動(dòng)畫故事板和風(fēng)格的任意組合來(lái)自定義動(dòng)畫。然后在圖表數(shù)據(jù)對(duì)象中將PlotElementAnimation綁定至一個(gè)新LoadAnimation屬性,并可以完成圖表動(dòng)畫的創(chuàng)建。
以下是一個(gè)通過(guò)改變透明度來(lái)實(shí)現(xiàn)圖表淡入加載效果的代碼,通過(guò)創(chuàng)建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>
接下來(lái)創(chuàng)建資源
<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資源,非常簡(jiǎn)單易用,效果如下。
創(chuàng)建縮放動(dòng)畫,需要用到Style和Storyboard中的另外兩個(gè)屬性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,就可以創(chuàng)建以下效果。
使用RotateTransform便可以創(chuàng)建旋轉(zhuǎn)動(dòng)畫,還可以自定義原點(diǎn)(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,就能夠創(chuàng)建復(fù)合動(dòng)畫了。
<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>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)