データ バインディングを使用して WPF でアニメーションを作成しようとしています。私は MatrixAnimationUsingPath を使用して、形状がパスをたどるようにしています。パスは、viewModel で配列として表されます。点[]。ポイント プロパティを viwmodel にバインドして、MatrixAnimationUsingPath で使用できるようにするにはどうすればよいですか。
<Storyboard>
<MatrixAnimationUsingPath Storyboard.TargetName="MyMatrixTransform"
Storyboard.TargetProperty="Matrix" DoesRotateWithTangent="True"
Duration="0:0:5" RepeatBehavior="Forever">
<MatrixAnimationUsingPath.PathGeometry>
<PathGeometry>
// WHAT TO PUT HERE!
</PathGeometry>
</MatrixAnimationUsingPath.PathGeometry>
</MatrixAnimationUsingPath>
</Storyboard>
値コンバーターを使用してポイントからパスを作成できましたが、MatrixAnimationUsingPath でパスを使用できません。
<Path Name="MyPath" StrokeThickness="2" Data="{Binding Path=Points, Converter={StaticResource ResourceKey=PointsToPathConverter}}">
コメントの後に追加:
以前は、値コンバーターをあまり扱っていませんでした。私が使用したコンバーターは、オンラインで見つけました。変更できますか?
[ValueConversion(typeof(Point[]), typeof(Geometry))]
public class PointsToPathConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Point[] points = (Point[])value;
if (points.Length > 0)
{
Point start = points[0];
List<LineSegment> segments = new List<LineSegment>();
for (int i = 1; i < points.Length; i++)
{
segments.Add(new LineSegment(points[i], true));
}
PathFigure figure = new PathFigure(start, segments, false); //true if closed
PathGeometry geometry = new PathGeometry();
geometry.Figures.Add(figure);
return geometry;
}
else
{
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
#endregion
}