2013-12-11 45 views
1

我關注此Guide in codeprojectWPF自定義名稱空間不起作用

所以,我將其添加到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中使用這樣的:

<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> 

我有以下錯誤:

命名空間中不存在名稱「ResultListView」 「http://my-project.com/wpf

「ResultListViewModel」這個名字並不在命名空間中 「http://my-project.com/wpf

我是不是做錯了什麼。 這不是對另一個項目的引用,所有這些代碼都在同一個VS2012項目中。

任何想法?請?

謝謝!

+0

你有沒有試過1.重建和2.重新啓動VS? – Gusdor

+0

是的,我做到了。 –

+1

重複的http://stackoverflow.com/q/2760504/643085。 'XmlnsDefinition'僅適用於其他程序集中的名稱空間,不適用於相同的程序集。 –

回答

2

XML名稱空間映射在聲明映射的相同程序集內的XAML文件中通常不起作用。在該程序集中,您通常必須使用clr-namespace URI。

相關問題