2

Another WPF question/problem. I have made a User Control (called Edit). Problem is that upon building (and also in the editor), I get the following compile error:

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

I also note two things:

(1) The Build Action of the .xaml-file (of the User Control) is set to Page. The Build Action of the code-behind file is set to Compile.

(2) When I let the programm run, despite the error, everything runs fine, BUT then again I haven't integrated the User Control into the application as this point (i.e. the User Control isn't used by the Main Window or any other part of the application at this point).

Here is the .xaml code:

<UserControl x:Class="Testing.Views.Edit"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Testing"
        xmlns:views="clr-namespace:Testing.Views" >

    <DockPanel Margin="5">
        <Border DockPanel.Dock="Top">
            <TextBlock>This is a User Control!</TextBlock>
        </Border>
    </DockPanel>

</UserControl>

The code-behind:

using System;    
using Testing;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace Testing.Views
{
    public partial class Edit : UserControl
    {
        public Edit()
        {
            InitializeComponent();
        }

    }
}

Anyone have an idea? Thanks.

Holland
  • 395
  • 9
  • 22
  • What happens if you do use the UserControl? any other errors? – Lewis Taylor Dec 22 '15 at 17:28
  • I'll report in about 15 minutes... – Holland Dec 22 '15 at 17:43
  • 1
    You messed up with namespaces names. If everything is in place right now, do Clean and/or Rebuild. – E-Bat Dec 22 '15 at 18:01
  • When I add to the MainWindow, where xmlns:views="clr-namespace:Testing.Views", the compiler complains that "The name Edit does not exist in the namespace "clr-namespace:Testing.Views"." This is likely related to the building error I reported in my original question, seems to be a namespace-related problem, but I don't see the solution at the moment. – Holland Dec 22 '15 at 18:02
  • I also note that intellisense does recognize the name Edit, when I'm typing in the MainWindow.xaml file... – Holland Dec 22 '15 at 18:12
  • Are you sure that the error message is pointing to Testing.Views.Edit user control? Do you Clean and Rebuild? – E-Bat Dec 22 '15 at 18:14
  • Yes, I've cleaned and rebuilt. But, extremely strangely, when I changed the content of the UserControl to this: it suddenly worked. Did I make a syntax error within the User Control or something, I'm wondering. – Holland Dec 22 '15 at 18:18
  • Still experimenting, I'll report back when I know more... ;-) – Holland Dec 22 '15 at 18:25
  • Well, I thought the problem had gone away, because the blue underlining and message in the error had disappeared, but the errors about not finding the user control in the namespace still appeared when I compiled. Somehow the original message has disappeared, but now I get the namespace messages. I'll make a new question, because the situation has changed. – Holland Dec 22 '15 at 18:44

0 Answers0