MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Samples / BasePage

Class BasePage

SampleApps/webview2_sample_uwp/Pages/BasePage.cs:13–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace WebView2_UWP.Pages
12{
13 public class BasePage : Page
14 {
15 public BasePage()
16 {
17 Unloaded += BasePage_Unloaded;
18 }
19
20 private void BasePage_Unloaded(object sender, RoutedEventArgs e)
21 {
22 // The garbage collector can be slow to dispose of the
23 // webviews. Manually free the resources being used by
24 // the webviews since they are no longer needed after
25 // the page has been unloaded.
26 CloseAllWebViews(this);
27 }
28
29 private void CloseAllWebViews(DependencyObject root)
30 {
31 for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
32 {
33 var childVisual = VisualTreeHelper.GetChild(root, i);
34 CloseAllWebViews(childVisual);
35
36 if (childVisual is WebView2 webView)
37 {
38 webView.Close();
39 }
40 }
41 }
42 }
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected