I am building a C#/WPF application using VS2013, and I have the following class definition (in the same assembly of the running application):
namespace MyNamespace { public class MyKey { public MyKey() { } public string name = ""; } }
In MainWindow.xaml I have:
<Window x:Class="MyNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyNamespace" Title="MainWindow" Height="350" Width="525" WindowState="Maximized" WindowStyle="None"> <Window.Resources> <local:MyKey x:Key="key" /> </Window.Resources> ...
VS keeps reporting that
The name "MyKey" does not exist in namespace "clr-namespace:MyNamespace"
Any ideas?
P.S. I tried the following solutions (from already posted questions in stackoverflow) but none of them worked:
xmlns:local="clr-namespace:MyNamespace;assembly="
Edit: Additional info: The target architecture: X64, target framework: .Net 4.5
But for purposes of how WPF works with XAML namespaces, you can generally think of XAML namespaces in terms of a default XAML namespace, the XAML language namespace, and any further XAML namespaces as mapped by your XAML markup directly to specific backing CLR namespaces and referenced assemblies.
Do preliminary reading and then ask your questions if something is unclear. Just because a name exists in a namespace, doesn't mean you can just use it! Generally speaking (and certainly for beginners) follow the simple rule: one project, one namespace.
If the assembly is different from the namespace in which your class is contained, you have to specfiy it explicitly. Show activity on this post. In my case it was because of other compile errors.
More than one XmlnsDefinitionAttribute can exist to map multiple CLR namespaces to the same XML namespace. Once mapped, members of those namespaces can also be referenced without full qualification if desired by providing the appropriate using statement in the partial-class code-behind page.
One common solution to this known VS bug that you haven't specified as having tried is changing the build target platform.
If your current build target platform is x64, change to x86. If it's currently x86, change to x64.
Clean and Build solution for new target platform.
Change back to desired target platform and re-build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With