1
我遇到了RenderTargetBitmap问题,因为我无法在后台线程上更改绑定属性后始终如一地获取更新的呈现。WPF确保RenderTargetBitmap已更新后台线程更改的绑定值
以下是我有:
// Update a property on an INotifyPropertyChanged view model
// This runs on a background thread
viewModel.SomeBoundProperty += 10;
// Flush dispatcher queue (from http://stackoverflow.com/a/2596035/612510)
_lcd.Dispatcher.Invoke(() => {}, System.Windows.Threading.DispatcherPriority.Loaded);
// Render the updated control
_lcd.Dispatcher.Invoke(() =>
{
_lcd.Measure(new System.Windows.Size(240, 160));
_lcd.Arrange(new System.Windows.Rect(0, 0, 240, 160));
_lcd.UpdateLayout();
_renderTarget.Render(_lcd);
}
可惜的是,约一半的时候,我发现了控制与新值更新之前渲染,而另一半是正确更新。
从我理解的WPF自动调度属性更改通知到UI线程。我如何确保在执行渲染之前全部处理这些分派的通知?如果我确认SomeBoundProperty
已在分派器线程上更新,则此代码正常工作,但对于此特定应用程序而言,这并不理想。
有什么建议吗?