我正在嘗試使用StaticExtension使用的相同名稱空間:StaticType.Property語法在WPF標記擴展中執行某種類型的解析。該擴展在運行時和Visual Studio設計器中工作正常,但在Expression Blend中失敗。經過一些調試後,我發現在調用IXamlTypeResolver.Resolve()時發生故障。IXAmlTypeResolver.Resolve在Blend中失敗
// Parse Static=properties:Resources.HelloWorld like static resource
int index = this.Static.IndexOf('.');
if (index == -1)
throw new ArgumentException(Resources.InvalidStaticBindingSyntax + ": " +
this.Static);
// resolve properties:Resources
string typeName = this.Static.Substring(0, index);
IXamlTypeResolver service = _serviceProvider.GetService(typeof(IXamlTypeResolver))
as IXamlTypeResolver;
Type memberType = service.Resolve(typeName);
string propName = this.Static.Substring(index + 1);
localized = memberType.GetProperty(propName,
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.FlattenHierarchy)
.GetValue(memberType, null);
問題是service.Resolve(typeName)失敗,但只在Blend中。
看看StaticExtension與Reflector和MS使用的代碼看起來沒有太大的不同。
它看起來像一個安全問題 - 但我甚至試圖簽署和GAC的大會,它仍然沒有完全一樣。
難倒。