WPF自定义命名空间无法正常工作 [英] WPF Custom Namespaces not working

查看:193
本文介绍了WPF自定义命名空间无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这个的指南$ C $的CProject

所以,我把它添加到AssemblyInfo.cs中:

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")]

然后,我用它像这样在XAML:

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:

名为ResultListView中不存在的命名空间    http://my-project.com/wpf

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

名为ResultListViewModel中不存在的命名空间    http://my-project.com/wpf

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

难道我做错了什么。 这不是一个引用到另一个项目,这一切code是在同一个VS2012的项目。

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

你知道吗?请?

谢谢!

推荐答案

XML命名空间的映射往往不会在XAML文件相同的组件声明映射内工作。在该程序集,您通常需要使用 CLR命名空间的URI。

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.

这篇关于WPF自定义命名空间无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆