![](/img/trans.png)
[英]The tag 'XXX' does not exist in XML namespace 'clr-namespace:XXX'
[英]The tag 'ViewModelLocator' does not exist in XML namespace clr-namespace:XXX
我嘗試了許多其他解決方案但沒有任何成功。 我有一個名為ViewModelLocator
的類,它位於我的可移植類庫中。 它有一個名為ViewModels
的屬性,它的類型為Dictionay<K, V>
然后我有一個引用可移植類庫的Windows Phone 8項目。 我在WP8 app.xaml中添加了以下內容:
<Application
x:Class="Kaizen.WP8.Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:test="clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable">
<Application.Resources>
<test:ViewModelLocator x:Key="ViewModelLocator">
<test:ViewModelLocator.ViewModels>
<test:SampleViewModel x:Key="sampleVM"/>
</test:ViewModelLocator.ViewModels>
</test:ViewModelLocator>
</Application.Resources>
</Application>
當我在標簽上按F12時,它會導航到我的pcl中的正確類和/或屬性。 這表明VS知道對象,但是當我嘗試構建時,我收到以下錯誤:
XML命名空間'clr-namespace中不存在標記'ViewModelLocator':Foo.Core.Portable.ViewModel; assembly = Foo.Core.Portable'。
XML命名空間'clr-namespace:Foo.Core.Portable.ViewModel; assembly = Foo.Core.Portable'中不存在標記'SampleViewModel'。
有人可以提供一些幫助嗎?
[更新]我在我的pcl項目中引用了mvvm light的pcl版本。 這就是ViewModelLocator
類的樣子:
public class ViewModelLocator
{
public dynamic this[string viewModelName]
{
get
{
if (this.ViewModels.ContainsKey(viewModelName))
{
return this.ViewModels[viewModelName];
}
else
{
return null;
}
}
}
public Dictionary<string, ViewModelBase> ViewModels { get; set; }
public ViewModelLocator()
{
this.ViewModels = new Dictionary<string, ViewModelBase>();
}
}
我的WP8項目也使用了mvvm light pcl程序集。 我注意到,如果我使用ViewModelBase
類作為字典值,那么當我得到錯誤時。 這是因為在兩個項目之間使用mvvm light pcl存在問題?! [更新]
提前謝謝了!! 親切的問候,
我剛剛在.Net 4.5項目中遇到了這個問題。 我的解決方案是更改為.Net 4.0,忽略警告,然后更改回.Net 4.5。 然后問題就消失了。
不知道這對其他人是否可行,但它對我有用。
最好的祝福。
好的,所以我不確定我在第一次嘗試時做錯了什么,但我重新創建了解決方案並執行了或多或少相同的步驟,我沒有再收到錯誤?! O_O
我知道這有點晚了但我在使用WPF桌面應用程序和控件庫時遇到了同樣的問題。 該庫的默認目標框架是.Net 4,但我在Visual Studio中創建后的桌面應用程序默認情況下是使用.Net 4客戶端配置文件創建的。 我將桌面應用程序從.Net 4客戶端配置文件更改為.Net 4並且工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.