2012-08-10 49 views
6

我們有一個帶有用戶控件的WPF頁面,我們使用BitmapCache - 當我們試圖通過用空路徑(New Path())更新屬性(數據綁定)來清除此元素時,它沒有完全刷新/清除。如果我稍微改變窗口大小,BitmapCache激活的區域將被完全清除。WPF的BitmapCache沒有完全清除

清除/刷新使用BitmapCache的元素有什麼特別的做法嗎?

這是我們的代碼:

<me:ScrollViewer 
    RenderedWaves="{Binding RenderedWaves}" 
    ItemTemplate="{DynamicResource DataTemplateForWaveItem}" 
    ItemsPanel="{DynamicResource ItemsPanelTemplateForWaveItems}" 
    CacheMode="BitmapCache" /> 

我想我固定的,但它並不是屢試不爽......

此代碼設置路徑沒有按」 t立即更新BitmapCache:

Protected WriteOnly Property SetGraph As Path 
Set(value As Path) 
    If value Is Nothing Then value = GetEmptyPath() 
    _graph = value 
    OnPropertyChanged(New PropertyChangedEventArgs(PropertyNameGraph)) 
End Set 
End Property 

而這種代碼更新有時:

Protected WriteOnly Property SetGraph As Path 
Set(value As Path) 
    UIDispatcherLocator.UIDispatcher.Invoke(Sub() 
               If value Is Nothing Then value = GetEmptyPath() 
               _graph = value 
              End Sub, Threading.DispatcherPriority.Background) 
    OnPropertyChanged(New PropertyChangedEventArgs(PropertyNameGraph)) 
End Set 
End Property 
+0

您可能會告訴我們更多一點?爲什麼這麼複雜? – 2012-08-10 13:25:04

+0

如果我是一個博彩人,我會說你有vidya卡問題。你能提供一個最小的例子來表明repros? – Will 2012-08-10 13:26:47

+0

您可以從代碼隱藏中調用InvalidateVisual(),以查看是否有幫助 – ekholm 2012-08-10 13:30:30

回答

0

可能你剛剛作出了一個新的事件的對象必要時開火,並呼籲將設置對象時=到由一個使用聲明,如果創建的臨時新對象你可以使它從system.idisposable繼承,或者如果你完成後將它設置爲null?我不知道它的代碼關閉我的頭頂,但類似:

MyEvent += new event(object b); 

event(object b) 
{ 
    using (custom_ScrollViewer = new custom_ScrollViewer) 
{ 
OnScreen_ScrollViewer = Custom_ScrollViewer; 

}; 
// or 
custom_ScrollViewer = new custom_ScrollViewer; 
OnScreen_ScrollViewer = Custom_ScrollViewer; 
custom_ScrollViewer = null; 

}