Microsoft Developer Network > Forenhomepage > Windows Presentation Foundation (WPF) > The name 'InitializeComponent' does not exist....
Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetThe name 'InitializeComponent' does not exist....

  • Dienstag, 12. September 2006 20:06Christian Sparre TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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.

Antworten

  • Dienstag, 12. September 2006 21:41Christian Sparre TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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

Alle Antworten

  • Dienstag, 12. September 2006 20:26Rob RelyeaModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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

     

  • Dienstag, 12. September 2006 21:41Christian Sparre TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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

  • Dienstag, 12. September 2006 23:48Rob RelyeaModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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

  • Samstag, 17. März 2007 20:15Mark K. MillerMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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.

  • Sonntag, 18. März 2007 14:02Rob RelyeaModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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

  • Montag, 5. Januar 2009 11:20Mr. Bungle TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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.