How to turn off animations in WPF Toolkit charts

主宰稳场 提交于 2019-12-22 07:59:12

问题


Is there a way to turn off the animations in Xaml directly? The animations are really sluggish as my chart has many points.


回答1:


i have downloaded the latest source code at http://wpf.codeplex.com/SourceControl/list/changesets

my idea is, to remove the animation by changing the style for the different chart series (chart points, DataPointStyle)

example for charting:PieDataPoint

try to remove the animation for the shown data and take your own style with a given key (x:key="myStyle" -> DataPointStyle="{StaticResource myStyle}")

and remove Opacity="0" at <Grid x:Name="Root" Opacity="0">

remove this visual state group from your style

<VisualStateGroup x:Name="RevealStates">
    <VisualStateGroup.Transitions>
        <VisualTransition GeneratedDuration="0:0:0.5" />
    </VisualStateGroup.Transitions>
    <VisualState x:Name="Shown">
        <Storyboard>
            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
        </Storyboard>
    </VisualState>
    <VisualState x:Name="Hidden">
        <Storyboard>
            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
        </Storyboard>
    </VisualState>
</VisualStateGroup>

EDIT

This is the changed style.

<!--  charting:PieDataPoint  -->
<Style TargetType="charting:PieDataPoint">
    <Setter Property="Background" Value="Orange" />
    <Setter Property="BorderBrush" Value="White" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="RatioStringFormat" Value="{}{0:p2}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="charting:PieDataPoint">
                <Grid x:Name="Root" Opacity="0">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="MouseOverHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Unselected" />
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="SelectionHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Path x:Name="Slice" Data="{TemplateBinding Geometry}" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeMiterLimit="1">
                        <ToolTipService.ToolTip>
                            <StackPanel>
                                <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                <ContentControl Content="{TemplateBinding FormattedRatio}" />
                            </StackPanel>
                        </ToolTipService.ToolTip>
                    </Path>
                    <Path x:Name="SelectionHighlight" Data="{TemplateBinding GeometrySelection}" Fill="Red" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" />
                    <Path x:Name="MouseOverHighlight" Data="{TemplateBinding GeometryHighlight}" Fill="White" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

After my first attempt to remove the animation, I wanted to give up, because it has not worked.

But then I looked upon me with the reflector to the source code and have found a way that it still works.

Setting the DataPointStyle unfortunately is not enough, I think it's a bug.

<chartingToolkit:Chart Margin="8">

  <chartingToolkit:Chart.Series>
    <chartingToolkit:BarSeries x:Name="barSeries"
                                Title="Experience"
                                DataPointStyle="{StaticResource myBarStyle}">
    </chartingToolkit:BarSeries>
  </chartingToolkit:Chart.Series>

</chartingToolkit:Chart>

In the constructor of the control where the chart is included simply execute the following.

this.barSeries.RefreshStyles();

hope this helps



来源:https://stackoverflow.com/questions/3352659/how-to-turn-off-animations-in-wpf-toolkit-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!