從其他程序集中引用xaml中的類時出現問題。「clr-namespace ...」中不存在MC3074 - 類型
在同樣的解決方案中,我有兩個項目。一個名爲Controls(用於保存用戶控件)和一個名爲DataBinding(保存轉換器/驗證規則)。在一個控件中,im試圖在xaml中引用驗證規則:
<Binding.ValidationRules>
<databind:Validators.FileExistsRule />
</Binding.ValidationRules>
我的項目引用包含我的類的項目。香港專業教育學院在我Control.xaml頂部添加了此聲明:
xmlns:databind="clr-namespace:GuiParts.DataBinding;assembly=DataBinding"
然而,當我編譯,我得到一個錯誤:
The tag 'Validators.FileExistsRule' does not exist in XML namespace 'clr-namespace:GuiParts.DataBinding;assembly=DataBinding'.
類肯定存在,我可以把它叫做代碼後面沒有問題,但沒有通過xaml。如果我將課程移到同一個項目中,我再也沒有問題了。香港專業教育學院看到這裏的其他問題,並嘗試以下操作:
- 清洗和重建的所有相關項目
- 確保所有項目都瞄準同一版本的.NET(4.0,全部檔案)的
- 拆除從命名空間定義的末尾'裝配'定義。
以上都沒有奏效。任何關於我哪裏出錯的建議?
編輯
我FILEEXISTS驗證:
namespace GuiParts.DataBinding.Validators
{
/// <summary>
/// Validates that the file with the specified name exists
/// </summary>
public class FileExistsRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
ValidationResult res = null;
res = (! File.Exists((string)value))
? new ValidationResult(false, "File does not exist")
: new ValidationResult(true, null);
return res;
}
}
}
我可以調用以下代碼背後沒有任何錯誤:
new GuiParts.DataBinding.Validators.FileExistsRule();
所以香港專業教育學院得到了我的名字空間等正確的。
你方法可以是1行語句:'返回File.Exists((字符串)值)?新的ValidationResult(false,「文件不存在。」):new ValidationResult(true,null);' – 2012-07-17 19:41:53
有沒有想到這一點? – 2013-01-08 00:30:23