![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Target name cannot be found when animating storyboard programmatically Hi there, I've been trying out the WinFX stuff and have been running into major problems trying to get a storyboard to animate. Here is a code snippit. The Class that contains this code is inherited from Canvas. WPFPage::WPFPage(int width, int height) { this->Height = height; this->Width = width; this->Background = gcnew SolidColorBrush(Colors::White); // load bitmap images BitmapImage^ bitmap1 = gcnew BitmapImage(gcnew Uri( "C:\\Documents and Settings\\stan\\My Documents\\Visual Studio 2005\\Projects\\WindowsApplication1\\Images\\phoenixanimation501.bmp")); // create onscreen images Image^ image1 = gcnew Image(); image1->Name = "image1"; image1->Source = bitmap1; image1->Width = 269; Canvas::SetTop(image1, 100); Canvas::SetLeft(image1, 10); this->Children->Add(image1); // create storyboard storyboard = gcnew Storyboard(); storyboard->RepeatBehavior = RepeatBehavior::Forever; storyboard->Name = "storyboard1"; // double animation using keyframes DoubleAnimationUsingKeyFrames^ danim1 = gcnew DoubleAnimationUsingKeyFrames(); storyboard->SetTargetName(danim1, image1->Name); storyboard->SetTargetProperty(danim1, gcnew PropertyPath(Image::OpacityProperty)); // keyframes DiscreteDoubleKeyFrame^ kf1_1 = gcnew DiscreteDoubleKeyFrame(); kf1_1->Value = 1; kf1_1->KeyTime = KeyTime::FromTimeSpan(TimeSpan(0, 0, 0, 0, 30)); DiscreteDoubleKeyFrame^ kf1_2 = gcnew DiscreteDoubleKeyFrame(); kf1_2->Value = 0; kf1_2->KeyTime = KeyTime::FromTimeSpan(TimeSpan(0, 0, 0, 0, 180)); danim1->KeyFrames->Add(kf1_1); danim1->KeyFrames->Add(kf1_2); storyboard->Children->Add(danim1); storyboard->Begin(this); } When I try to run this, Begin(this) causes the program to break and complain about not being able to find "image1" which was set via the TargetName method of Storyboard. since "this"'s children does have the image added to it with the name property set, why is the storyboard not able to find this? Any help would be greatly appreciated! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically Hmm, the plot thickens. For fun, I added the following code to the program: if(this->FindName("image1") == NULL) { image1->Width = 400; } else { image1->Width = 100; } When I do this, I end up with a small image (pass condition). This means that the object name does indeed exist in the canvas and WinFX was able to find it via FindName. If that is the case, why is the storyboard not able to find it? Does anyone know if this is a bug or if I am doing something wrong? |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically When coding animationts I think you have to register the object you want to animate using RegisterName method http://windowssdk.msdn.microsoft.com...ee38cf79ea.asp and read section Targeting Objects and Properties Regards Ranjit <stanley_r_eisenberg@raytheon.com> wrote in message news:1147644678.019333.267690@i39g2000cwa.googlegroups.com... > Hmm, the plot thickens. > > For fun, I added the following code to the program: > > if(this->FindName("image1") == NULL) { > image1->Width = 400; > } else { > image1->Width = 100; > } > > When I do this, I end up with a small image (pass condition). This > means that the object name does indeed exist in the canvas and WinFX > was able to find it via FindName. > > If that is the case, why is the storyboard not able to find it? > > Does anyone know if this is a bug or if I am doing something wrong? > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically Thanks alot Ranj, I'll give that a try tonight and will post updates on here. I've been very impressed with WinFX so far, but this problem is the main thing preventing me on using the tech in an upcoming project, hopefully all goes well! |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically Hi Ranj, Just tried the RegisterName method, but it didn't work. I added the follow (the class inherits from Canvas): this->RegisterName("image1", image1); And I received the following error message: An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll Additional information: No NameScope found to register the Name 'image1'. image1 is of type Image, perhaps this is a Freezable and doesn't have a NameScope property or something? |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically you could try NameScope.SetNameScope(this, new NameScope()); <stanley_r_eisenberg@raytheon.com> wrote in message news:1147743158.513201.293960@u72g2000cwu.googlegroups.com... > Hi Ranj, > > Just tried the RegisterName method, but it didn't work. > > I added the follow (the class inherits from Canvas): > > this->RegisterName("image1", image1); > > And I received the following error message: > > An unhandled exception of type 'System.InvalidOperationException' > occurred in PresentationFramework.dll Additional information: No > NameScope found to register the Name 'image1'. > > image1 is of type Image, perhaps this is a Freezable and doesn't have a > NameScope property or something? > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically Ah, thanks Ranj, I didn't know I could do that! I'll give that a try tonight, hopefully that does the trick... we've got to be getting close! :-) Thanks again! |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Target name cannot be found when animating storyboard programmatically Woot! Thanks Ranj, that did the trick! Thanks again for the help, your knowledge of WinFX has surely made my experience a lot more enjoyable! :-) |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Aero icons stop animating | Vista performance & maintenance | |||