Microsoft Developer Network > Página principal de foros > Windows Presentation Foundation (WPF) > The name 'InitializeComponent' does not exist....
Formular una preguntaFormular una pregunta
 

RespondidaThe name 'InitializeComponent' does not exist....

  • martes, 12 de septiembre de 2006 20:06Christian Sparre Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    I'm trying to create a UserControl in a Class Library and it all works just fine. I can see everything in designer, but when I'm trying to build my solution I get the following error.

    The name 'InitializeComponent' does not exist in the current context

    And that's it, as it says I don't have that method in my .cs codebehind file. But the thing is when I create a UserControl in a WinFX Windows Application I can build it just fine, so i must be missing something. I tried removing the method call and that let me build it, but when creating a new instance and adding it to my Grid nothing happend. 

    Any idea what I'm doing wrong.

    I am somewhat new to the .NET platform ( great idea jumping on the .NET 3.0 wagon then huh  ) But I would really like some help on this issue, because I do not have the slightest idea where to go from here.

Respuestas

  • martes, 12 de septiembre de 2006 21:41Christian Sparre Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Thank's Rob, but it didn't seem to help, everything was set up as you said.

    I cruised a bit more around and stumbled over this

    http://blogs.msdn.com/mhendersblog/archive/2005/10/03/476536.aspx ( something about hosting WPF in WinForms, quite clever actually  )

    I't seems that when creating a DLL project (as with WinForms) Visual Studio can't handle "WPF/WinFX file types", so all I had to do was add <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" /> in my .csproj file.

    Now it works like a charm

    PS. thank's for keeping us up to date on the RC1 and Sept. CTP releases

Todas las respuestas

  • martes, 12 de septiembre de 2006 20:26Rob RelyeaModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    The initializeComponent routine is created in the .g.cs file that is created during build.  (see obj\debug\...)

    Make sure your XAML file has a build action of "Page" to create that file.

     

    Also, make sure that the partial classes in .xaml.cs and .g.cs match.

    Hope that helps.

    Thanks, Rob Relyea
    WPF Team
    http://rrelyea.spaces.live.com

     

  • martes, 12 de septiembre de 2006 21:41Christian Sparre Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Thank's Rob, but it didn't seem to help, everything was set up as you said.

    I cruised a bit more around and stumbled over this

    http://blogs.msdn.com/mhendersblog/archive/2005/10/03/476536.aspx ( something about hosting WPF in WinForms, quite clever actually  )

    I't seems that when creating a DLL project (as with WinForms) Visual Studio can't handle "WPF/WinFX file types", so all I had to do was add <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" /> in my .csproj file.

    Now it works like a charm

    PS. thank's for keeping us up to date on the RC1 and Sept. CTP releases

  • martes, 12 de septiembre de 2006 23:48Rob RelyeaModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Ah, yes, I should have noticed you said "Class Library".

    If you use the Wpf Custom Control Project, that will have been done for you.

    Thanks, Rob

  • sábado, 17 de marzo de 2007 20:15Mark K. MillerMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Rob, we need better discoverability on this. The error message needs to do a better job at guiding us to the solution.

    Update: I'm not seeing a "Wpf Custom Control Project" project option inside VS 2005. In the Add New Project dialog I only see:

    Windows Application
    Class Library
    Windows Control Library
    Windows Application (WPF) 

    And several other objects that are obviously not relevant.

  • domingo, 18 de marzo de 2007 14:02Rob RelyeaModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Hey Mark-

    With the VS 2005 extensions, you are looking for "Custom Control Library (WPF)" which is not listed in the main nodes (C# or VB), but can only be found under the "Net Framework 3.0" node of Project Types.

    In VS "Orcas" March 2007 CTP, VB & C# are a bit different:

    • VB:  Under the "Windows" node of VB projects, there is "WPF Custom Control Library" and "WPF User Control Library".
    • C#: Under the top level node and the "Windows" node, there is "WPF User Control Library" available.

    (my guess is that the orcas one may change a little bit...)

    Hope that helps.

    -Rob

  • lunes, 05 de enero de 2009 11:20Mr. Bungle Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Just came across this compile error when I created a new WPF user control in VS 2008.  I had used Visual Studio's 'Refactor' to change the class name, but it failed to rename the class name in the XAML (only in code-behind).  Changing the class name there to match fixed the problem.