UWP Web view get blinks one time after loading

Nimalika 21 Reputation points
2019-11-22T09:58:32.06+00:00

How can we fix web view blink issue?

XAML code

util:WebViewCustomProperties.HtmlContent="{Binding CourseDescription}"

WebViewCustomProperties Class

// "HtmlContent" attached property for a WebView		
        
public static readonly DependencyProperty HtmlContentProperty =
           DependencyProperty.RegisterAttached("HtmlContent", typeof(string), typeof(WebViewCustomProperties), new PropertyMetadata("", OnHtmlHtmlContentChanged));


// Getter and Setter		
        
public static string GetHtmlContent(DependencyObject obj) { return (string)obj.GetValue(HtmlContentProperty); }
        
public static void SetHtmlContent(DependencyObject obj, string value) { obj.SetValue(HtmlContentProperty, value); }


 // Handler for property changes in the DataContext : set the WebView		
        
private static void OnHtmlHtmlContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            WebView wv = d as WebView;
            if (wv != null)
            {
                wv.NavigateToString((string)e.NewValue);
            }
        }

Issue Video

web view blink issue

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Richard Zhang-MSFT 6,936 Reputation points
    2019-11-22T11:46:43.683+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    WebView page blink may be an animation issue. You can try to disable the transition animation between pages to solve.

    MyFrame.Navigate(typeof(WebViewPage), null, new SuppressNavigationTransitionInfo());
    

    If you like page animation, you can try another method:

    Create the WebView in code-behind

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        view = new WebView(WebViewExecutionMode.SameThread);
        MyGrid.Children.Add(view);
        var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/MyPage.html"));
        string content = await FileIO.ReadTextAsync(file);
        view.NavigateToString(content);
    }
    

    It can also fix the problem of page blink, you can choose as needed.

    Thanks


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.