アニメーションでの作業の小さな例、モデルのプロパティのバリエーション、アニメーションでの作業ではありません
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="440" Width="732" Loaded="Window_Loaded"
MouseLeftButtonDown="Grid_MouseLeftButtonDown" MouseLeftButtonUp="Grid_MouseLeftButtonUp" MouseMove="Grid_MouseMove">
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Canvas Name="canvMain" Height="360" Width="710" Grid.Row="1">
<Rectangle Name="Zombi" Width="20" Height="40" Stroke="Black" StrokeThickness="2" Canvas.Bottom="0" Canvas.Right="{Binding Path=X, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"></Rectangle>
</Canvas>
</Grid>
public double X
{
get { return _x; }
set
{
if (!double.IsNaN(value))
{
_x = value;
OnPropertyChanged("X");
}
}
}
double pixelMetr = 0.715;
private int GetPixel(double metr)
{
return Convert.ToInt32(metr / pixelMetr);
}
private void StartZombi()
{
double distance = 250;
double maxTime = (new Random()).Next(5, 10);
PathGeometry animationPath = new PathGeometry();
LineGeometry lineGeometry = new LineGeometry();
lineGeometry.StartPoint = new Point(0, 0);
lineGeometry.EndPoint = new Point(GetPixel(distance), 0);
animationPath.AddGeometry(lineGeometry);
DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath();
animationX.PathGeometry = animationPath;
animationX.Duration = TimeSpan.FromSeconds(maxTime);
animationX.Source = PathAnimationSource.X;
Storyboard.SetTarget(animationX, Zombi);
Storyboard.SetTargetProperty(animationX, new PropertyPath(Canvas.RightProperty));
Storyboard pathAnimationStoryboard = new Storyboard();
pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
pathAnimationStoryboard.Children.Add(animationX);
pathAnimationStoryboard.Begin(this);
}
こんにちは、プロパティの変更が機能しないのはなぜですか。アニメーションの実行時に、プロパティ ' canvas.right ' の現在の値を取得する必要があります。
これは xaml コードです。