public static object UIThreadGetValue(this DependencyObject me, DependencyProperty dp)
{
object retVal = null;
if (me != null)
{
if (Application.Current.Dispatcher != System.Windows.Threading.Dispatcher.CurrentDispatcher)
{
retVal = Application.Current.Dispatcher.Invoke(
new Func<DependencyProperty, object>(me.GetValue), dp);
}
else
{
retVal = me.GetValue(dp);
}
}
else
{
retVal = null;
}
return retVal;
}