Holland
Holland

Reputation: 415

WPF: InitializeComponent doesn't exist for User Control

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.

Upvotes: 2

Views: 3340

Answers (0)

Related Questions