The tag 'Employee' does not exist in the XML namespace 'clr-namespace: XYZ; assembly = XYZ '

I tried a simple WPF application. XAML Code:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfApplication1;assembly=WpfApplication1"
        Title="My First WPF Demo" Height="350" Width="525">
    <Window.Resources>
        <sys:Int32 x:Key="i">10</sys:Int32>
        <local:Employee x:Key="emp2"></local:Employee> --> THIS LINE
    </Window.Resources>
    <StackPanel>
        <TextBox x:Name="txtName" FontSize="18" Margin="20"></TextBox>
        <Button x:Name="btnClickMe" FontSize="18" Margin="20" 
                Click="btnClickMe_Click">Click Me</Button>
        <TextBlock x:Name="lblName" FontSize="18" Margin="20"></TextBlock>
        <Label x:Name="lblEmpInfo" FontSize="18" Margin="20"></Label>
        <Label x:Name="lblEmpInfo2" FontSize="18" Margin="20"></Label>
    </StackPanel>
</Window>

I have an Employee class that looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApplication1
{
    public class Employee
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

When I try to build my project, I get an error message:

Error 1 The tag 'Employee' does not exist in the XML namespace 'CLR names: WpfApplication1; assembly = WpfApplication1 '. Line 9 Position 10.

+4
source share
4 answers

use this method in your case: XMLNS: local = "CLR names: WpfApplication"

0
source

They didn’t check, but ... did you try to remove the part assembly=WpfApplication1? Leaving onlyxmlns:local="clr-namespace:WpfApplication1"

0
source

(Windows 7, Visual Studio 2012 Update 4) . ( , , ​​ ), " ":

  • MainWindow.xaml( Employee.cs )
  • ! ( , Visual Studio Employee.cs, XAML)

,

0

, , :

<local:MyClass Name="TagName"></local:MyClass>

To:

<local:MyClass Name="TagName"/>

:

Because 'MyClass' is implemented in the same assembly, you must set the x:Name attribute rather than the Name attribute. 

, :

<local:MyClass x:Name="TagName"/>

:

 <local:MyClass x:Name="TagName"></local:MyClass>
0

Source: https://habr.com/ru/post/1599864/


All Articles