我有一個前幾天做了一個自定義WPF控件:無效自己的WPF控件
public class MapContext : FrameworkElement{
//....
protected override void OnRender(DrawingContext dc) {
// Draw the map
if (mapDrawing != null) dc.DrawDrawing(mapDrawing);
}
的mapDrawing
繪圖在另一個線程所有以顯示幾何計算更新,該線程將更新用戶界面通過調用InvalidateVisual()
:
Application.Current.Dispatcher.Invoke(DispatcherPriority.Render, new Action(delegate { InvalidateVisual(); }));
在InvalidateVisual
,MSDN documentation說:
使元素的渲染無效,並強制完成新的佈局傳遞。 OnRender在佈局週期完成後調用。
這不是我想要的行爲,因爲MapContext
控件佈局沒有改變。只有裏面的圖紙已經改變。
問題 有沒有做一個完整的佈局通過被稱爲強迫OnRender
方法的正確方法?
在此先感謝
這正是我的問題的方法,但在某些時候我需要將這些DrawingVisuals扔到用戶界面。請參閱我的帖子在這裏http://stackoverflow.com/questions/8521789/data-binding-performance-issues – GETah
不知道爲什麼你轉換爲位圖? DrawingVisual是可見元素的最低級別。可見的一切都源於它,因此要在屏幕上顯示一個,只需將其設置爲Window,Panel或其他ContentPresenter的Content屬性。 – GazTheDestroyer
我的地圖不是靜態的,圖形每秒變化5次,所以我認爲在處理下一個視圖時準備顯示位圖會很好。 – GETah