为什么我的XAML控件没有出现在代码隐藏? [英] Why are my XAML controls not showing up in code-behind?
问题描述
我启动到Windows开发者预览的今天,希望能得到一些代码出来,进入一个正常运作的Metro应用。我很高兴为推出Windows应用商店,我想成为其中的一部分。所以,我火了VS11 Express和开始编码。我几乎都起不了一行时:
I booted into the Windows Developer Preview today, hoping to get some code out and into a functioning Metro application. I'm excited for the launch of the Windows Store, and I wanted to be a part of it. So I fire up VS11 Express, and start coding. I barely even get out one line when:
查看这个名字并不在目前的情况下存在
"The name 'View' does not exist in the current context"
所以,我回到我的XAML页面。我挖过来,你瞧,我命名的视图按钮仍然存在,用下面的代码:
So I go back to my XAML page. I dig around, and lo and behold, my button named View is still there, with the following code:
<按钮名称=查看CONTENT =查看帮助页面的HorizontalAlignment =左HEIGHT =142保证金=765,275,0,0VerticalAlignment =评出的WIDTH =456字号=48前景=黑背景= 橙色BorderBrush =黑/>
我看到没有错XAML。但是,我用C#唯一的经验就是通过Windows Phone 7的所以我做了一些研究。我看没有什么错我的代码。
I saw nothing wrong with that XAML. However, my only experience with C# is through Windows Phone 7. So I do a bit of research. And I see nothing wrong with my code.
到底是什么错在这里?这个工作与桌面Windows和WP7!
What the heck is wrong here? This worked with desktop Windows AND WP7!
我怎样才能防止这种情况发生,并且它为什么发生?
How can I prevent this from happening, and why is it happening?
我刚回到我的项目,并意识到,我忘了保存。然后我按了按Ctrl传统移-S保存一切。我回到MainPage.xaml.cs中和LO的标签,你看,它的作品!没有错误!为什么会出现这种情况。
I just returned to my project and realized that I had forgotten to save. I then pressed the traditional Ctrl-Shift-S to save everything. I went back to the tab of MainPage.xaml.cs and lo and behold, it works! No error! Why did this happen?
推荐答案
尝试使用 X:名称
而不是香草名称
。使用名称
对冲突造成潜在的,而 X:名称
确保将命名标识符指定的值
Try using x:Name
instead of vanilla Name
. The use of Name
creates the potential for a conflict while x:Name
ensures it will name the identifier the specified value
有是在MSDN可用更详细的解释。请参阅命名元素栏目
There is a more detailed explanation available on MSDN. See the "Named Elements" section
- http://msdn.microsoft.com/en-us/library/ms752059.aspx
这篇关于为什么我的XAML控件没有出现在代码隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!