问题描述
我正在尝试将 youtube 视频嵌入到 Webbrowser 中,但是它只显示一个空白屏幕
<Webbrowser util:WebbrowserUtility.BindableSource="{Binding UrlContent}"/>
DI:
public static void BindableSourcePropertyChanged(DependencyObject o,DependencyPropertyChangedEventArgs e)
{
Webbrowser browser = o as Webbrowser;
if (browser != null)
{
string uri = e.NewValue as string;
if (string.IsNullOrEmpty(uri)) return;
browser.NavigatetoString(uri);
}
}
输出:
尝试过:
- 格式化的 HTML
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<head>
</head>
<iframe width='560' height='315' src='http://www.youtube.com/embed/diB65scQU' frameborder='0' allowfullscreen></iframe>
<body>
</body>
</html>
结果 - 相同 - 只是一个空白视图
知道为什么吗?
解决方法
你可以用WebView2控件代替,它是官方的替代品,看看WebView2。 见WebView2Samples on github