InitializeComponent does not exist in the current context

来源:互联网 发布:淘宝买三角梅哪家好 编辑:程序博客网 时间:2024/05/23 11:48



InitializeComponent_Silverlight

 

You’ve made some changes to your Silverlight application and all of the sudden your MainPage.xamlwill not compile because InitializeComponent does not exist in the current context or theLinksStackPanel.Children doesn’t exist in the current context. This is a frustrating problem until you know what causes it.

 

The root cause of the problem is that your x:Classdirective in the “xaml” page somehow got lost or is not in sync with your code-behind file.

 

Did you just copy a MainPage from another project, or backed up project?  Copying the MainPage.xaml and the code-behind doesn’t seem to fix the problem by itself.

 

First, fix the x:Class reference in your MainPage.xaml

Make sure that your x:Class is named properly and that the namespace matches that of your application! If you have already checked this then don’t worry there is one more thing that probably went wrong.

Second, fix the “Build Action” of your MainPage.xaml

This one took me several hours, and a few headaches to find. I compared a working project to the non-working one and notices that the “Build Action” of MainPage.xaml must have changed when manipulating the window. The Build Action was set to “Content”.

The Build Action should be set to “Page

Simply highlight the MainPage.xaml in your Solution Explorer and in the properties check out the Build Action. Once you fix this, you will no longer have problems with InitializeComponent and it will fix problems with LinksStackPanel.Children not existing in the context.


InitializeComponent_Silverlight

 

You’ve made some changes to your Silverlight application and all of the sudden your MainPage.xamlwill not compile because InitializeComponent does not exist in the current context or theLinksStackPanel.Children doesn’t exist in the current context. This is a frustrating problem until you know what causes it.

 

The root cause of the problem is that your x:Classdirective in the “xaml” page somehow got lost or is not in sync with your code-behind file.

 

Did you just copy a MainPage from another project, or backed up project?  Copying the MainPage.xaml and the code-behind doesn’t seem to fix the problem by itself.

 

First, fix the x:Class reference in your MainPage.xaml

Make sure that your x:Class is named properly and that the namespace matches that of your application! If you have already checked this then don’t worry there is one more thing that probably went wrong.

Second, fix the “Build Action” of your MainPage.xaml

This one took me several hours, and a few headaches to find. I compared a working project to the non-working one and notices that the “Build Action” of MainPage.xaml must have changed when manipulating the window. The Build Action was set to “Content”.

The Build Action should be set to “Page

Simply highlight the MainPage.xaml in your Solution Explorer and in the properties check out the Build Action. Once you fix this, you will no longer have problems with InitializeComponent and it will fix problems with LinksStackPanel.Children not existing in the context.

0 0
原创粉丝点击