我有一个依赖属性在一个类中,我们称之为“SomethingControl”:
public static readonly DependencyProperty SomethingProperty = DependencyProperty.Register("Something", typeof(Something), typeof(SomethingControl), new UIPropertyMetadata(SomethingGotSet));
我已经定义了传递到UIPropertyMetadata构造函数中的回调方法为异步:
private async static void SomethingGotSet(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (SomethingControl)d;
if (control != null)
{
control.SomeOtherProperty = await AsynchronousMethodCall();
}
}
这样做安全吗?会不会在UI线程上导致死锁或问题?我已经测试过了,似乎一切都正常,但我在MSDN文档中找不到使用异步属性回调方法的相关内容。