c# - 在 Pivot 中使用 WebBrowser 时在生产中崩溃

标签 c# windows-phone-7 windows-phone-8 windows-phone webbrowser-control

我知道将 WebBrowser 放在 Pivot/RadSlideView 控件中是个坏主意。 无论如何我还是这样做了:

<phone:PhoneApplicationPage
    x:Class="**.HtmlView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    mc:Ignorable="d"
    Style="{StaticResource LeafPageNavigationStyle}">

    <controls:Pivot x:Name="Html" ItemsSource="{Binding Items}" 
                    Style="{StaticResource HeaderlessPivot}">
        <controls:Pivot.ItemTemplate>
            <DataTemplate>
                <phone:WebBrowser Source="{Binding}" />
            </DataTemplate>
        </controls:Pivot.ItemTemplate>
    </controls:Pivot>

</phone:PhoneApplicationPage>

基本上我想使用 Pivot 在我通过我的 ViewModel 提供的 URI 中滑动 HTML 文档数组,它只是将数组包装在 Caliburn.Micro OneActive Conductor 中:

namespace DSBMobile.ViewModels
{
    public class HtmlViewModel : Conductor<Uri>.Collection.OneActive
    {
        private readonly IUnburyableState<Uri[], HtmlViewModel> _state;

        public HtmlViewModel(IUnburyableState<Uri[], HtmlViewModel> state)
        {
            _state = state;
            Items.AddRange(_state.State.ForceGetValue());
        }
    }
}

在我手动部署的调试和发布版本中运行良好。该应用程序通过了商店强加的所有测试,但是当我尝试在应用程序中打开这个特定 View 时,它崩溃了,没有任何机会重定向到 Telerik MessageBox。

一旦我移除外部 Pivot 并相应地调整 ViewModel,它就会顺利运行。正如我所说,崩溃只发生在生产中。 Application.UnhandledException 处理程序无法让应用吞下异常并显示错误。

这真的很复杂,几个月来一直困扰着我。任何人都可以解决这个错误或指出一个有值(value)的方向吗?对于显示多个有效的 Web 链接,我也很感激更像 WP 的建议。

最佳答案

事实证明我得到了一个 UnauthorizedAccessException,解释说我缺少 ID_CAP_WEBBROWSERCOMPONENT 功能,而我没有。这让我很困惑,直到我终于看到了 docs :

When you create a WebBrowser control in XAML, you must specify a value for the P:System.Windows.FrameworkElement.Name property for that control so that the Windows Phone Capability Detection Tool can properly detect and grant the right capabilities for your app. For more info about the Windows Phone Capability Detection Tool, see How to determine app capabilities.

设置 x:Name 后,我终于可以拥有无​​崩溃的体验。 就我个人而言,这是有史以来最烦人的错误。这有助于我在商店上传测试版,尽管我没有支付任何开发者费用,这是我事先不知道的。

TLDR:RTFM。

关于c# - 在 Pivot 中使用 WebBrowser 时在生产中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102694/

相关文章:

sqlite.cs 找不到 sqlite3 和社区

c# - 这是 WCF 服务应用程序的有效使用吗

计算单词出现次数的字典的 C# 实现在输出中返回重复单词

c# - 构造函数中的 ASP.NET Core 选项依赖项

windows-phone-7 - 在 MVVMCross 应用程序中处理异常的建议方法是什么?

javascript - 独立存储中 HTML 中的 JS/CSS 加载问题

c# - 协助打开从 C# VSTO Excel 项目到关闭的 .xlsx 文件的连接(不打开 .xlsx 文件)

c# - 将 JSON 反序列化为对象时出现问题

c# - 如何使用 Autocomplete Textbox WP Toolkit 完成多个单词?

c# - 如何在 XAML 中访问我的 ListBox 的 DataTemplate(但不是绑定(bind))中的 TextBlock?