内部连接点示例

This commit is contained in:
艾竹
2023-02-04 16:38:56 +08:00
parent 0d6debe87f
commit e8f91abd68
12 changed files with 153 additions and 21 deletions

View File

@@ -30,18 +30,18 @@ namespace AIStudio.Wpf.DiagramDesigner
private void LineControl_Unloaded(object sender, RoutedEventArgs e)
{
if (this.DataContext is ConnectionViewModel connector)
if (this.DataContext is ConnectionViewModel connector && connector.ColorViewModel != null)
{
connector.PropertyChanged -= Connector_PropertyChanged;
connector.ColorViewModel.PropertyChanged -= Connector_PropertyChanged;
}
_story?.Stop();
}
private async void PathAnimation_Loaded(object sender, RoutedEventArgs e)
{
if (this.DataContext is ConnectionViewModel connector)
if (this.DataContext is ConnectionViewModel connector && connector.ColorViewModel != null)
{
connector.PropertyChanged -= Connector_PropertyChanged;
connector.ColorViewModel.PropertyChanged -= Connector_PropertyChanged;
connector.PropertyChanged += Connector_PropertyChanged;
}
this.ball.Visibility = Visibility.Collapsed;
@@ -52,7 +52,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
switch (e.PropertyName)
{
case nameof(ConnectionViewModel.PathGeneratorResult):
case nameof(ColorViewModel.LineAnimation):
case nameof(ColorViewModel.LineAnimationDuration):
await DoAnimation();
break;
@@ -71,10 +72,10 @@ namespace AIStudio.Wpf.DiagramDesigner
ball.Visibility = Visibility.Collapsed;
break;
case LineAnimation.PathAnimation:
PathAnimation();
PathAnimation(connector.ColorViewModel.LineAnimationDuration);
break;
case LineAnimation.DashAnimation:
DashAnimation();
DashAnimation(connector.ColorViewModel.LineAnimationDuration);
break;
}
}
@@ -82,7 +83,7 @@ namespace AIStudio.Wpf.DiagramDesigner
Storyboard _story;
private void PathAnimation()
private void PathAnimation(double second)
{
this.ball.Visibility = Visibility.Visible;
@@ -105,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath();
animationX.PathGeometry = this.line.Data?.GetFlattenedPathGeometry();
animationX.Source = PathAnimationSource.X;
animationX.Duration = new Duration(TimeSpan.FromSeconds(2));
animationX.Duration = new Duration(TimeSpan.FromSeconds(second));
DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath();
animationY.PathGeometry = this.line.Data?.GetFlattenedPathGeometry();
@@ -135,12 +136,12 @@ namespace AIStudio.Wpf.DiagramDesigner
}
private void DashAnimation()
private void DashAnimation(double second)
{
this.ball.Visibility = Visibility.Collapsed;
var animation = new DoubleAnimation(0, -10, new Duration(TimeSpan.FromSeconds(0.5)))
var animation = new DoubleAnimation(0, -10, new Duration(TimeSpan.FromSeconds(second)))
{
RepeatBehavior = RepeatBehavior.Forever,
};