我正在使用TryFindResource API来获取画笔对象。但是返回的对象无权访问调用线程-为什么?
我的代码:
public static Brush GetErrorBrush()
{
object resValue = Application.Current.TryFindResource("Colors_Error_SCBrush");
if(resValue!=null && resValue is DependencyObject)
{
if(!(resValue as DependencyObject).CheckAccess())
{
//If we dont do this, while assiging the value to Calling API, it fails with exception "Must create DependencySource on same Thread as the DependencyObject."
resValue = Brushes.Red;
}
}
return resValue != null ? (Brush)resValue : Brushes.DarkRed;
}
此外,我如何找到谁是该依赖对象的父对象-哪个线程拥有它?
引用thread。
谢谢, 拉什米