6

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?

EDIT

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?

1
  • I had the same issue in VS2012 - ctrl-shift-s fixed it! Bizarre. Commented Oct 18, 2012 at 19:08

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

See above: it simply worked after a simple save. Also, I originally had x:Name in there and that didn't make a change. Switching it around didn't do the trick; it turned out that saving "fixed" the error. BTW, x:Name would always be my first choice. Great answer, but in this case I already tried that and it didn't work. I think it's a bug in Visual Studio 11.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.