キャンバス上でスケール変換をアニメーション化するために、C#でストーリーボードを作成しました。スケール変換はレイアウト変換です。アニメーションのC#コードは次のとおりです。
Storyboard Configuring = new Storyboard();
if (NexusRoot != null)
{
var current = (NexusRoot.LayoutTransform as ScaleTransform).ScaleX;
Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
myDoubleAnimation1.Duration = duration;
Configuring.Children.Add(myDoubleAnimation1);
myDoubleAnimation1.From = current;
myDoubleAnimation1.To = scale;
Storyboard.SetTarget(myDoubleAnimation1, NexusRoot);
Storyboard.SetTargetProperty(myDoubleAnimation1, (PropertyPath)new PropertyPathConverter().ConvertFromString("(UIElement.LayoutTransform).(ScaleTransform.ScaleX)"));
DoubleAnimation myDoubleAnimation2 = new DoubleAnimation();
myDoubleAnimation2.Duration = duration;
Configuring.Children.Add(myDoubleAnimation2);
myDoubleAnimation2.From = current;
myDoubleAnimation2.To = scale;
Storyboard.SetTargetName(myDoubleAnimation2, "NexusRoot");
Storyboard.SetTargetProperty(myDoubleAnimation2, (PropertyPath)new PropertyPathConverter().ConvertFromString("(UIElement.LayoutTransform).(ScaleTransform.ScaleY)"));
}
このアニメーションを実行すると、次の例外がスローされます。
System.ArgumentNullExceptionがキャッチされましたMessage="値をnullにすることはできません。\r\ nパラメータ名:dp"
Source = "WindowsBase" ParamName = "dp" StackTrace:at System.Windows.DependencyObject.GetValue(DependencyProperty dp)at System.Windows.Media.Animation.Storyboard.ProcessComplexPath(HybridDictionary clockMappings、DependencyObject targetObject、PropertyPath path、AnimationClock AnimationClock、HandoffBehavior handoffBehavior、Int64 layer)at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock、DependencyObject containsObject、INameScope nameScope、DependencyObject parentObject、String parentObjectName、PropertyPath parentPropertyPath、HandoffBehavior handoffBehavior、HybridDictionary clockMappings、Int64 Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock、DependencyObject containsObject、INameScope nameScope、DependencyObject parentObject、String parentObjectName、PropertyPath parentPropertyPath、HandoffBehavior handoffBehavior、HybridDictionary clockMappings、Int64 layer)at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containsObject、INameScope nameScope、HandoffBehavior handoffBレイヤー)C:\ Documents and Settings \ lbeaver \ Desktop \ StormFront \ WPF \ StormFront \ StormFront \ NexusDesigner.xamlのStormFront.NexusDesigner.ScaleCanvasAnimation(Double scale)のSystem.Windows.Media.Animation.Storyboard.Begin() cs:line 544 InnerException:HandoffBehavior handoffBehavior、HybridDictionary clockMappings、Int64 layer)at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containsObject、INameScope nameScope、HandoffBehavior handoffBehavior、Boolean isControllable、Int64 layer)at System.Windows.Media.Animation.Storyboard.Be )C:\ Documents and Settings \ lbeaver \ Desktop \ StormFront \ WPF \ StormFront \ StormFront \ NexusDesigner.xaml.cs:line 544 InnerExceptionのStormFront.NexusDesigner.ScaleCanvasAnimation(Double scale):HandoffBehavior handoffBehavior、HybridDictionary clockMappings、Int64 layer)at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containsObject、INameScope nameScope、HandoffBehavior handoffBehavior、Boolean isControllable、Int64 layer)at System.Windows.Media.Animation.Storyboard.Be )C:\ Documents and Settings \ lbeaver \ Desktop \ StormFront \ WPF \ StormFront \ StormFront \ NexusDesigner.xaml.cs:line 544 InnerExceptionのStormFront.NexusDesigner.ScaleCanvasAnimation(Double scale):C:\ Documents and Settings \ lbeaver \ Desktop \ StormFront \ WPF \ StormFront \ StormFront \ NexusDesigner.xaml.cs:line 544 InnerExceptionのStormFront.NexusDesigner.ScaleCanvasAnimation(Double scale)のStoryboard.Begin():C:\ Documents and Settings \ lbeaver \ Desktop \ StormFront \ WPF \ StormFront \ StormFront \ NexusDesigner.xaml.cs:line 544 InnerExceptionのStormFront.NexusDesigner.ScaleCanvasAnimation(Double scale)のStoryboard.Begin():
この例外の発生を防ぐにはどうすればよいですか?