Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To shut down a WPF page, you can simply close the window that hosts the page or remove it from the visual tree. To erase the page's cache, you can clear any variables or data structures that hold information related to the page. If you want to clear the page's visual cache, you can use the following code to clear the rendering cache:

this.Dispatcher.Invoke(() =>
{
    var visual = PresentationSource.FromVisual(this) as Visual;
    if (visual != null)
    {
        var cache = VisualTreeHelper.GetDrawingContext(visual).RenderCache;
        if (cache != null)
        {
            cache.Clear();
        }
    }
});

This code clears the visual cache for the current page. If you want to clear the cache for a specific element, you can replace this with that element's reference.