1
如何在wpf中設置動畫路徑數據?我們有一系列模板化的Silverlight-5控件,它們改變了這個屬性;這些控件需要適應wpf工作。在wpf中,當VSM嘗試更改狀態時,它會崩潰,但存在以下例外情況:更改wpf故事板中的Path.Data
無法使用「System.Windows.Media」爲'System.Windows.Shapes.Path'上的'Data'屬性製作動畫。 Animation.ObjectAnimationUsingKeyFrames'
內部異常: 應用於'Data'屬性的動畫計算[XXX-The path data-]的當前值,該值不是該屬性的有效值。
下面是一個按鈕控制的例子:從一個圓形到一個星形的路徑 - 這怎麼能在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>
傳說!非常感謝你:) – user495625
不客氣,很高興幫助:) –