// 利用 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
));
}