Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# does not contain a definition for "InitializeComponent" and name "controlName" does not exist in current context

I've been developing a windows phone app in a team since June. Everything worked fine with all the syncs until today. I synced the project and vs started giving me the errors

  • "WindowsPhoneApp.MainPage" does not contain a definition for InitializeComponent (and in all other pages, even App)
  • The name "controlName" does not exist in the current context (this happens in all the pages)

I didn't change anything, it worked fine yesterday. Classes names on XAML match the names in code-behind.
I've tried exited all vs instances but the problems are still there.

like image 325
Usr Avatar asked Sep 27 '15 10:09

Usr


1 Answers

For me, the problem was following:


Project structure

Project\Views\Page1.xaml
Project\Views\Page1.xaml.cs

The error in Page1.xaml.cs on abovementioned page constructor:

public sealed partial class Page1 : Page
{
    public Page1()
    {
        this.InitializeComponent();
    }
}

Xaml file

<Page
    x:Class="App1.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

should be x:Class="App1.Views.Page1"

so just typo in the class name.

like image 75
Arsinclair Avatar answered Oct 29 '22 14:10

Arsinclair