locked
The name 'InitializeComponent' does not exist in the current context App.xaml.cs RRS feed

  • Question

  • Hi,
    I'm very new to Silverlight/Expression Blend 3. I've created a sample project but when I try to build it I get the error 'The name 'InitializeComponent' does not exist in the current context'  The file the error refers to is 'App.xaml.cs'.   Any assistance would be appreciated.
    Thanks
    Friday, January 29, 2010 3:32 PM

All replies

  • Hi,
          This is probably because the x:Class attribute in App.xaml doesn't match the class name in App.xaml.cs. Please follow these steps and let us know if it works for you.

    1. Open App.xaml and check x:Class attribute (Ex: SilverlightApplication101.App)
    2. Open App.xaml.cs and check if the namespace and class name match (namespace: SilverlightApplication101, class: App), if not fix it.
    3. Build

    Not it should build fine.

    Thanks,
    Navit Saxena
    • Proposed as answer by navits - MSFT Friday, January 29, 2010 7:40 PM
    Friday, January 29, 2010 7:39 PM
  • i mgeeting an error Error 

     

    1 The name 'InitializeComponent' does not exist in the current context C:\Users\Iram\Documents\Visual Studio 2008\Projects\SilverlightDB\SilverlightDB\MainPage.xaml.cs 23 13 SilverlightDB

     

    in file MainPage.xaml

     

    any urgent reply would highly appreciated

     

     

    Monday, August 30, 2010 2:36 AM
  • here is teh piece of code

     

    <UserControl xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="SilverlightDB.Page"
    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
    Width="400" Height="300">
    
      <Border BorderBrush="Black" BorderThickness="1">
    
        <Grid x:Name="LayoutRoot" Background="white" ShowGridLines="False">
    
       
        </Grid>
    
         </Border>
      
      
    
    </UserControl>
    
    
    Monday, August 30, 2010 2:38 AM
  • Hi,

    I just expirence the same problem. You should add

    <ResourceDictionary.MergedDictionaries/> to App.xaml file.

     

    Monday, September 12, 2011 8:10 PM
  • Also the App.cs defines the call as 

    this.InitializeComponent();

      

    Try that in the MainPage.cs after you set the x:Class to the same namespace as your class 

    So in the MainPage.xmal

     x:Class="AzurePhone.Phone.MainPage"

    and my class definition

    namespace AzurePhone.Phone
    {
        public partial class MainPage : PhoneApplicationPageINotifyPropertyChanged
        {


    DJC

    • Proposed as answer by Denis Cilliers Friday, February 10, 2012 11:49 AM
    Friday, February 10, 2012 11:48 AM
  • Try ensuring that the App.xaml file has its Build Action set to "Page" in the Properties panel.
    • Proposed as answer by michn Friday, June 1, 2012 11:03 AM
    Friday, June 1, 2012 11:03 AM
  • Thanks, I checked and checked the names.  Finally I cut and pasted the name and bang it worked.  Thanks again.
    Friday, November 15, 2013 5:13 PM