我们有一个带有用户控件的WPF页面,其中使用了BitmapCache-当我们尝试通过使用空Path(New Path())更新属性(Data Binding)来清除此元素时,它并未完全刷新/清除。如果我稍微改变窗口大小,则BitmapCache处于活动状态的区域将被完全清除。
有什么特别的事情可以清除/刷新使用BitmapCache的元素?
这是我们的代码:
<me:ScrollViewer
RenderedWaves="{Binding RenderedWaves}"
ItemTemplate="{DynamicResource DataTemplateForWaveItem}"
ItemsPanel="{DynamicResource ItemsPanelTemplateForWaveItems}"
CacheMode="BitmapCache" />
我以为我已修复它,但它并非每次都有效...
设置路径的以下代码不会立即更新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
最佳答案
如果您可以使它从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;
}