Why are my XAML controls not showing up in code?

Today I booted into the Windows Developer Preview, hoping to get some kind of code and enter the current Metro application. I am very happy for the launch of the Windows Store, and I wanted to be part of this. So I launch VS11 Express and start coding. I barely even selected one row when:

"Name" View "does not exist in the current context"

So, I am returning to my XAML page. I dig, and lo and behold, my button with the name “View” still exists 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 have not seen anything wrong with this XAML. However, my only experience with C # is through Windows Phone 7. Therefore, I understand a bit. And I do not see anything wrong with my code.

What is wrong here? This worked with Windows desktop and WP7!

How can I prevent this, and why is this happening?

EDIT

I just returned to my project and realized that I forgot to save. Then I pressed the traditional Ctrl-Shift-S to save everything. I returned to the MainPage.xaml.cs tab, and here it works! No mistake! Why did this happen?

+6
source share
1 answer

Try using x:Name instead of vanilla Name . Using Name creates potential for conflict, and x:Name ensures that it calls the identifier the specified value

MSDN has a more detailed explanation. See Section Named Items.

+9
source

Source: https://habr.com/ru/post/905484/


All Articles