简体   繁体   English

RegisterName用户控件

[英]RegisterName UserControl

I have a WPF application with a grid and inside the grid I have a canvas control. 我有一个带有网格的WPF应用程序,并且在网格内部有一个画布控件。 I also created a user control that I add to the canvas control. 我还创建了一个添加到画布控件的用户控件。 I am creating a storyboard to animate that user control, but when I call myStoryboard.Begin(myUserControl) I always get the error: myControl name cannot be found in the name scope of 'ScoreBoard.Controls.ucWindow' (that is my control class). 我正在创建一个情节提要来对该用户控件进行动画处理,但是当我调用myStoryboard.Begin(myUserControl)时,总是出现错误:在“ ScoreBoard.Controls.ucWindow”(即我的控件类)的名称范围中找不到myControl名称)。

So I was looking for some solution and I found that I need to Create a NameScope so that Storyboards can be used and I need to register the name of my control. 因此,我在寻找一些解决方案时,发现需要创建一个NameScope,以便可以使用Storyboard,并且需要注册控件的名称。

I already tried both things but I still get that error. 我已经尝试过两种方法,但仍然会收到该错误。

I tried to create a NameScope for the window and for the canvas 我试图为窗口和画布创建一个NameScope

NameScope.SetNameScope(this, new NameScope());
//NameScope.SetNameScope(myCanvas, new NameScope());

and tried to register the name: 并尝试注册名称:

//myCanvas.RegisterName(myControl.Name, myUserControl);
this.RegisterName(myUserControl.Name, myUserControl);

myCanvas.Children.Add(myUserControl);

Does anyone know if I am missing something? 有人知道我是否想念什么吗?

Thanks in advance, 提前致谢,

Alberto 阿尔贝托

I think that I found a possible solution, when I was calling Storyboard.begin I was using Storyboard.SetTargetName, instead of Storyboard.SetTargetName I used Storyboard.SetTarget and now my code is working as I expected. 我认为当我调用Storyboard.begin时,我使用的是Storyboard.SetTargetName,而不是Storyboard.SetTargetName,而是使用Storyboard.SetTarget,找到了一个可能的解决方案,现在我的代码可以按预期工作。

Regards, 问候,

Alberto 阿尔贝托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM