【问题标题】:WPF's BitmapCache is not completely clearedWPF 的 BitmapCache 未完全清除
【发布时间】:2012-08-07 19:23:43
【问题描述】:

我们有一个带有用户控件的 WPF 页面,我们在其中使用 BitmapCache - 当我们尝试通过使用空路径 (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

【问题讨论】:

  • 您可以告诉我们更多信息吗?为什么这么复杂?
  • 如果我是一个赌徒,我会说你有 vidya 卡问题。你能提供一个最小的例子吗?
  • 您可以从代码隐藏中调用 InvalidateVisual(),看看是否有帮助
  • 您必须更改 UIElement 子树或这些属性 (EnableClearType\RenderAtScale) 以使缓存重新生成......请参阅blogs.msdn.com/b/llobo/archive/2009/11/10/…
  • 不要将 CacheMode 放在 ScrollViewer 上,而是将其放在您在 ItemsPanelTemplateForWaveItems 模板中使用的“面板”上。 ...然后尝试这个.....做一个 _graph = null (在 VB 中没有); OnPropertyChanged(New PropertyChangedEventArgs(PropertyNameGraph))..then _graph = value;和 OnPropertyChange 再次。

标签: .net wpf path bitmap rendering


【解决方案1】:

您是否可以在对象上创建一个新事件以在需要时触发,并且在调用时将 object = 设置为由 use 语句临时创建的新对象,如果您可以使其继承自 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;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 2015-06-06
    • 2011-01-28
    • 2012-12-14
    • 2018-08-04
    相关资源
    最近更新 更多