Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Custom Namespaces not working [duplicate]

I follow this Guide in codeproject.

So, I add this to the AssemblyInfo.cs:

[assembly: XmlnsPrefix("http://my-project.com/wpf", "g")]
[assembly: XmlnsDefinition("http://my-project.com/wpf", "GUI.View.Result")]
[assembly: XmlnsDefinition("http://my-project.com/wpf", "GUI.ViewModel.Result")]

Then I use it like this in xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:g="http://my-project.com/wpf">


    <DataTemplate DataType="{x:Type g:ResultListViewModel}">
        <g:ResultListView/>
    </DataTemplate>

</ResourceDictionary>

I have the following errors:

The name "ResultListView" does not exist in the namespace "http://my-project.com/wpf"

The name "ResultListViewModel" does not exist in the namespace "http://my-project.com/wpf"

Am I doing something wrong. This is not a reference to another project, all this code are in the same VS2012 project.

Any idea? Please?

Thanks!

like image 553
Fábio Ferreira Avatar asked Sep 11 '26 23:09

Fábio Ferreira


1 Answers

XML namespace mappings often do not work in XAML files within the same assembly declaring the mapping. Within that assembly, you will usually have to use the clr-namespace URIs.

like image 112
Mike Strobel Avatar answered Sep 13 '26 14:09

Mike Strobel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!