gpt4 book ai didi

c# - 在 WinrRT 应用程序中显示 HTML 内容

转载 作者:行者123 更新时间:2023-11-30 22:25:03 26 4
gpt4 key购买 nike

我在 IsolatedStorage 中有一些带有 HTML 文本的文件。如何在应用程序中显示它?我目前正在使用 WebView 及其 NavigateToString("html content") 属性,但效果不是很好,就像我无法显示任何 UI 元素一样它。对此有任何替代解决方案吗?

最佳答案

看起来解决方案是从 html 的渲染创建一个图像并显示它而不是实际的 WebView

来自 here ,大胆的我:

WebView 具有控件等其他UI 区域无法在WebView 之上呈现的特性。这是因为窗口区域是如何在内部处理的,特别是输入事件是如何处理的以及屏幕是如何绘制的。 如果您想呈现 HTML 内容并将其他 UI 元素放置在该 HTML 内容之上,您应该使用 WebViewBrush作为呈现区域。 WebView 仍然提供 HTML 源信息,您通过元素名称绑定(bind)和 SourceName 引用该 WebView属性(property)。 WebViewBrush 没有这个覆盖限制。

如果你想显示一个偶尔有重叠内容的交互式 WebView(例如下拉列表或应用栏),你可以在必要时暂时隐藏 WebView 控件,用一个使用 WebViewBrush 的元素替换它。充满。然后,当重叠内容不再存在时,您可以再次显示原始 WebView。有关详细信息,请参阅 WebView control sample.

找到示例代码 here :

//create webview and rectangle
<WebView x:Name="WebView6" />
<Rectangle x:Name="Rect1"/>

//put content in the webview
protected override void OnNavigatedTo(NavigationEventArgs e)
{

// Ensure that our Rectangle used to simulate the WebView is not shown initially
Rect1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

WebView6.Navigate(new Uri("http://www.bing.com"));
}

//make the rectangle visible when you want something over the top of the web content
Rect1.Visibility = Windows.UI.Xaml.Visibility.Visible;

//if the rectangle is visible, then hit the webview and put the content in the webviewbrush
if (Rect1.Visibility == Windows.UI.Xaml.Visibility.Visible)
{
WebViewBrush b = new WebViewBrush();
b.SourceName = "WebView6";
b.Redraw();
Rect1.Fill = b;
WebView6.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}

关于c# - 在 WinrRT 应用程序中显示 HTML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12487252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com