WPF Custom Namespaces not working [duplicate]

∥☆過路亽.° 提交于 2019-12-01 08:59:00

问题


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:


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.



来源:https://stackoverflow.com/questions/20522258/wpf-custom-namespaces-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!