Failed to resolve TargetName error in custom storyboard

In the WP50 silverlight application, I wanted to use storyboard animation on a specific event. The animation changes the button height property from x to y points (changed for the request).

I use the code below in my program

Storyboard myStoryBoard = new Storyboard(); myStoryBoard.Duration = new Duration(TimeSpan.FromMilliseconds(200)); DoubleAnimation myDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myDoubleAnimation, button1.Name); // button1 is normal button on UI Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Button.HeightProperty)); myDoubleAnimation.From = 200; myDoubleAnimation.To = 300; myStoryBoard.Children.Add(myDoubleAnimation); myStoryBoard.Begin(); 

when i run my code i click Unable to solve the problem named TargetName1

Is there any easy solution for my problem?

+4
source share
1 answer

I think you can use SetTargetName only if the Storyboard is in the visual tree. Instead, I suggest using SetTarget: http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard.settarget%28v=vs.95%29.aspx

 Storyboard.SetTarget(myDoubleAnimation, button1); 
+5
source

Source: https://habr.com/ru/post/1391271/


All Articles