Since you have a reference to the control, why not use Storyboard.SetTarget
instead?
Storyboard.SetTarget(heightAnimation, _newsControl);
سؤال
I'm using a custom control to display news data. I store the control in codebehind so I can display it without having to reload the information (takes anywhere from 2-5 seconds to perform all the tasks associated with populating the control). The news control is essentially a ScrollViewer
wrapped in a StackPanel
so there's not too much to it. I'm trying to animate the height and width of the control when I call a method, but I'm getting an InvalidOperationException
saying
"name cannot be found in the name scope of MainWindow"
I set the name of the control within the MainWindow constructor:
NewsControl _newsControl = new NewsControl() { Name = "newsControl" };
and I've even tried accessing it when I set the target of my DoubleAnimation
using the property value:
Storyboard.SetTargetName(heightAnimation, _newsControl.Name);
As mentioned, the control isn't in the XAML because I need the control in the codebehind anyway...so help?
المحلول
Since you have a reference to the control, why not use Storyboard.SetTarget
instead?
Storyboard.SetTarget(heightAnimation, _newsControl);