wpf - The name 'InitializeComponent' does not exist in the current context : strange behaviour -


i have created small wpf application , facing 1 problem. have below classes.

employee.cs

using system; using system.collections.generic; using system.linq; using system.text;  namespace staticresourcevsdynamicresource {     public class employee     {         public string strname;         public int nid;          public employee()         {             strname = "default name";             nid = -1;         }          public string name         {             get{return strname;}set{strname = value;}         }          public int id         {             get{return nid;}set{nid = value;}         }     } } 

mainwindow.xamal.cs

using system; using system.collections.generic; using system.linq; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes;  namespace staticresourcevsdynamicresource {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();         }          private void button1_click(object sender, routedeventargs e)         {             this.resources["objemployee"] = new employee { name = "changed employee", id = 100};              this.resources.add("mybrush",new solidcolorbrush(systemcolors.graytextcolor));                     }     } } 

mainwindow.xamal

<window x:class="staticresourcevsdynamicresource.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:staticresourcevsdynamicresource"     xmlns:sys="clr-namespace:system;assembly=mscorlib"     title="mainwindow" height="350" width="525"> <window.resources>             <x:arrayextension type="{x:type sys:string}" x:key="objnames">         <sys:string>a1</sys:string>         <sys:string>a2</sys:string>     </x:arrayextension>     <local:employee x:key="objemployee"></local:employee> </window.resources> <grid>                            <grid height="100" horizontalalignment="left" margin="281,12,0,0" name="grid3" verticalalignment="top" width="200" >                    <combobox itemssource="{staticresource resourcekey=objnames}" height="23" horizontalalignment="left" margin="48,37,0,0" name="combobox1" verticalalignment="top" width="120" />     </grid> </grid> 

above xaml code intresting. when build code didn't error. whatever reason shuffle position of <x:arrayextension> , <local:employee> , start getting below error.

the name 'initializecomponent' not exist in current context 

when declaring <local:employee> before <x:arrayextenion> getting error. sure has namespace, not able figure out. see below code causing compilation error.

<window.resources>     <local:employee x:key="objemployee"></local:employee>     <x:arrayextension type="{x:type sys:string}" x:key="objnames">         <sys:string>a1</sys:string>         <sys:string>a2</sys:string>     </x:arrayextension>         </window.resources> 

can help? seems strange problem is...

regards, hemant

i've had same problem. way resolved changing build action of xaml file page.

to credit source found solution: http://blog.mahop.net/post/compile-error-for-wpf-files-the-name-initializecomponent-does-not-exist-in-the-current-context.aspx


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -