여기 내 코드가 맞다고 생각합니다. 하지만 작동하지 않습니다. 어떤 종류의 버그입니까? 아니면 뭔가 잘못 됐나요? xaml에서 선 세그먼트를 애니메이션하면 잘 작동합니다.C#의 선 세그먼트를 애니메이션으로 작동하지 않습니까?
MainWindow.xaml :
<Window x:Class="XXX.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Canvas Name="canvas">
</Canvas>
</Window>
MainWindow.xaml.cs를 : 나를 위해
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
anim();
}
void anim()
{
Path path = new Path { Stroke = Brushes.Red, StrokeThickness = 1 };
PathGeometry pg = new PathGeometry();
PathFigureCollection pfc = new PathFigureCollection();
PathFigure pf = new PathFigure { StartPoint = new Point(50, 50) };
Storyboard sb = new Storyboard
{
Duration = System.Windows.Duration.Forever,
BeginTime = new TimeSpan(0, 0, 0),
RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever,
Name = "sb"
};
LineSegment ls = new LineSegment
{
IsSmoothJoin = true,
Point = new Point(80, 50)
};
PointAnimation pa = new PointAnimation
{
BeginTime = new TimeSpan(0, 0, 0, 0, 0),
Duration = new Duration(new TimeSpan(0, 0, 0, 1)),
From = new Point(0, 0),
To = new Point(0, 100),
RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever,
AutoReverse = true,
};
Storyboard.SetTarget(pa, ls);
Storyboard.SetTargetProperty(pa, new PropertyPath("Point"));
sb.Children.Add(pa);
pf.Segments.Add(ls);
pfc.Add(pf);
pg.Figures = pfc;
path.Data = pg;
canvas.Children.Add(path);
sb.Begin();
}
}
이 sb.Begin 모양(); 또는 storyboard.settarget/setproperty가 잘못 설정되었습니다. 그러나 이것이 사실이라면 무엇이 잘못 되었습니까?
int count = 0;
foreach(var f in pf.Segments)
{
f.BeginAnimation(LineSegment.PointProperty, (PointAnimation)sb.Children.ElementAt(count));
count++;
}
선분이있는 방법 BeginStoryboard가 없습니다 : 그것은 나를 위해하지만이 코드 대신 sb.begin() 작동으로 바보
당신은 http://stackoverflow.com/questions/15469283/how-does-one-animate-a-line-on-a-canvas-in-c/15469477#15469477 ([내 예]를 참조 할 수 있습니다) 적절한 기술을 사용하여 WPF에서 비슷한 작업을 수행하는 방법에 대해 설명합니다. 당신은 타이머를 사용하고 난 절차 적 코드에서 UI를 만드는 반대로 당신이 XAML을 사용한다이 경우에 ... –
는 것 같습니다. – masterkawaster
을 내장 스토리 보드를 사용하고 싶습니다처럼 –