Ask Your Question
0

How do I shut down a WPF page and erase its cache?

asked 2021-05-13 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-26 15:00:00 +0000

lalupa gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-13 11:00:00 +0000

Seen: 17 times

Last updated: Apr 26 '21