// 利用 ReadLocalValue 获取资源对象
var obj = tb_hello.ReadLocalValue(TextBlock.TextProperty);
if
(obj ==
null
)
{
Console.WriteLine(
"Is Null"
);
}
else
{
// 对象倒是获取了, 是个什么东东呢?
Console.WriteLine(obj.GetType().ToString());
// 通过这个能获取 obj 的类型为:
// System.Windows.ResourceReferenceExpression
// 存在于 PresentationFramework.dll 中
// 但郁闷的是无法直接声明和调用
// 无奈之下只能用反射了
Type type = obj.GetType();
foreach
(var pi
in
type.GetProperties())
{
Console.WriteLine(pi.Name);
}
// 发现居然只有一个属性: ResourceKey
PropertyInfo ifno = type.GetProperty(
"ResourceKey"
);
Console.WriteLine(ifno.GetValue(obj,
null
));
}