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"
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:
<Button Name="View" Content="View the help page" HorizontalAlignment="Left" Height="142" Margin="765,275,0,0" VerticalAlignment="Top" Width="456" FontSize="48" Foreground="Black" Background="Orange" BorderBrush="Black"/>
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.
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?
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?
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
There is a more detailed explanation available on MSDN. See the "Named Elements" section
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With