我正在尝试使用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的大会,它仍然没有完全一样。
难倒。