我在画布上有图表。当我点击图表我希望它缩放。我有这个代码。
<Canvas x:Name="SampleCanvas" Background="#F5F7F9" MouseLeftButtonDown="brdMovable_MouseLeftButtonDown" MouseLeftButtonUp="brdMovable_MouseLeftButtonUp" MouseMove="brdMovable_MouseMove" Height="570" Width="875">
<chartingToolkit:Chart x:Name="mcChart" Loaded="mcChart_Loaded" Width="400" Height="250" Canvas.Left="185" Canvas.Top="5"
Background="LightSteelBlue">
<chartingToolkit:Chart.RenderTransform>
<ScaleTransform x:Name="scaleTransform"></ScaleTransform>
</chartingToolkit:Chart.RenderTransform>
<chartingToolkit:Chart.Series>
<chartingToolkit:ColumnSeries Title="Experience" IndependentValueBinding="{Binding Path=ModelName}" DependentValueBinding="{Binding Path=SaleCount}">
</chartingToolkit:ColumnSeries>
</chartingToolkit:Chart.Series>
</chartingToolkit:Chart>
Storyboard storyBoard = new Storyboard();
///////// X Transform
DoubleAnimation ds = new DoubleAnimation();
storyBoard.Children.Add(ds);
ds.From = 1;
ds.To = 1.5;
ds.Duration = new Duration(TimeSpan.FromSeconds(2));
Storyboard.SetTargetName(ds, "scaleTransform");
Storyboard.SetTargetProperty(ds, new PropertyPath("(ScaleX)"));
////Y Transform
DoubleAnimation dsy = new DoubleAnimation();
storyBoard.Children.Add(dsy);
dsy.From = 1;
dsy.To = 1.5;
ds.Duration = new Duration(TimeSpan.FromSeconds(3));
Storyboard.SetTargetName(dsy, "scaleTransform");
Storyboard.SetTargetProperty(dsy, new PropertyPath("(ScaleY)"));
LayoutRoot.Resources.Remove("unique_id");
LayoutRoot.Resources.Add("unique_id",storyBoard);
storyBoard.Begin();
这首先在x方向显示输出,然后在y方向显示,但我一次想要两个方向。我们怎么能这样做?
感谢。
答案 0 :(得分:0)
我花了一点时间发现明显的情况:)你已经设置了第一个动画的持续时间两次(并且持续时间不同)。
应该是:
dsy.Duration = new Duration(TimeSpan.FromSeconds(2));
不是
ds.Duration = new Duration(TimeSpan.FromSeconds(3));