如何在wpf中动画路径数据?我们有一系列更改此属性的模板silverlight-5控件;这些控件需要调整以在wpf中工作。在wpf中,当VSM尝试更改状态时,它会崩溃,并出现以下异常:
无法使用'System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames‘为“”System.Windows.Shapes.Path“”上的“Data”属性设置动画
内部异常:应用于“”data“”属性的动画计算的当前值XXX-路径数据-不是该属性的有效值。“”
下面有一个按钮控件的例子:从圆圈到星形的路径-如何在wpf中实现?
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Path.Data)" Storyboard.TargetName="path">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>M 291.42858 512.36218 216.73569 387.62221 74.321018 416.8994 169.87441 307.31546 98.0216 180.91821 l 133.74814 57.01338 98.00719 -107.39498 -12.89251 144.82014 132.42459 60.0235 -141.71614 32.49039 z</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Viewbox>
<Path x:Name="path" Stroke="Black" Fill="Black" UseLayoutRounding="False" Data="m 357.14285 425.21933 c 0 71.79702 -58.20298 130 -130 130 -71.79701 0 -129.999997 -58.20298 -129.999997 -130 0 -71.79702 58.202987 -130 129.999997 -130 71.79702 0 130 58.20298 130 130 z"/>
</Viewbox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>发布于 2011-12-11 13:01:46
如果你不创建一个对象实例,它仍然是一个字符串,并且Data是Geometry,那么使用元素语法就没有意义了,只要把它包装在所说的标签中,它就应该可以工作了。
<DiscreteObjectKeyFrame.Value>
<Geometry>
M 291.42858 512.36218 216.73569 387.62221 74.321018 416.8994 169.87441 307.31546 98.0216 180.91821 l 133.74814 57.01338 98.00719 -107.39498 -12.89251 144.82014 132.42459 60.0235 -141.71614 32.49039 z
</Geometry>
</DiscreteObjectKeyFrame.Value>https://stackoverflow.com/questions/8461465
复制相似问题