tags:

views:

1247

answers:

8

This is very strange.

I have a XAML file that looks as follows...

<Window 
    x:Name="window"
    x:Class="ix.Production.Title"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Title" Height="768" Width="1024"
    Loaded="window_Loaded">

    <Window.Resources>
   etc...

And my code-beside that looks as follows...

using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Threading;

namespace ix.Production
{
    public partial class Title : Window
    {
        public Title()
        {
           InitializeComponent();
        }
    ....

This code refuses to compile because VS.NET insists that the InitializeComponent "does not exist in the current context."

Any ideas?

A: 

Your class is partial, so you should have another file that contains some other parts of your Title class (the InitializeComponent method for instance). Try to find that file, and see if the namespace in that file, is equal to the namespace of the file which contains the other parts of your class.

Frederik Gheysels
It says partial... but I wonder if the actual InitializeComponent is not generated somewhere by WPF? I'm not sure. Haven't been able to find it.
willem
+3  A: 

Your XAML says:

x:Class="ix.Production.Title"

while the actual class is ix.Outage.Title. Either change the XAML declaration or move the class to the ix.Production namespace.

Bojan Resnik
+1  A: 

Your namespaces don't match match:

x:Class="ix.Production.Title"
namespace ix.Outage { ...
rmoore
A: 

Looks like this was a kink in Visual Studio 2008.

If I create a new file (i.e. Title2), copy/paste the code and XAML, then change all 'Title' to 'Title2', everything works fine again.

willem
A: 

Hi Guys

I was strugling with the same issue here. What I did was to delete ALL the created files unde the debug folder, then rebuild the solution.

Regards, Petrus

Petrus
A: 

I had come across the same problem when i got a project sample from msdn. the issue was it was a 4.0 project and i did not have the 4.0 in my system, couple of referenced dlls were missing(system.xaml and another one) removed them. tried to compile, would always throw the initializecomponent method not found. went into the project properties changed the target framework to 3.5 and it is not complaining anymore.

A: 

I had the same problem with a VS2010 sample project that I manually reverted to VS2008. I found I had forgotten to set the Target Framework of the project to .NET Framework 3.5. It was empty in the project reverted to VS2008, initially set to 4.0 in the original VS2010 project.

To set Target Framework of a project, go to project properties, access the first tab flip called Application, and select .NET Framework 3.5 in the Target Framework dropdown.

Of course, I'd prefer Visual Studio giving me an error or at least a warning that I had not set my Target Framework, but hey, that's part of developing in Visual Studio, I guess. VS 2008 WPF project properties

Yngvar
A: 

One case I have seen this happening in when you copy paste a xaml control/window etc. InitializeComponent method exists in a corresponding .g.cs file that is automatically generated. In my case, after copy paste, Build Action for the xaml (in Properties window) was changed to "Resource". changed it to "Page" and it started working fine.

Hope this helps.

Thread which helped me with this: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2f755d30-bd8c-4f9b-b36a-9cb56bea15cd

gp