我使用一个自定义控件来显示新闻数据。我将控件存储在代码背后,这样就可以显示它,而无需重新加载信息(执行与填充控件相关的所有任务需要2-5秒的时间)。新闻控件本质上是一个包装在ScrollViewer中的StackPanel,所以它没有太多内容。当我调用一个方法时,我试图动画化控件的高度和宽度,但是我得到了一个InvalidOperationException语句
"name cannot be found in the name scope of MainWindow"
我在MainWindow构造函数中设置了控件的名称:
NewsControl _newsControl = new NewsControl() { Name = "newsControl" };当我使用属性值设置DoubleAnimation的目标时,我甚至尝试访问它:
Storyboard.SetTargetName(heightAnimation, _newsControl.Name);如前所述,该控件不在XAML中,因为我需要在代码背后的anyway...so帮助中的控件?
发布于 2013-07-23 20:24:39
既然您有对控件的引用,为什么不使用Storyboard.SetTarget呢?
Storyboard.SetTarget(heightAnimation, _newsControl);https://stackoverflow.com/questions/17820297
复制相似问题