WPF Custom Namespaces not working [duplicate]

2019-05-30 10:48发布

This question already has an answer here:

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!

1条回答
Rolldiameter
2楼-- · 2019-05-30 11:13

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.

查看更多
登录 后发表回答