在Pivot中使用WebBrowser时在生产中崩溃



我知道把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());
}
}
}

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

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

这真的很复杂,几个月以来一直困扰着我。有人能解决这个错误,或者给我指明一个有价值的方向吗?我也会感谢一个更WP风格的建议,显示多个有效的Web链接。

原来我得到了一个UnauthorizedAccessException,解释说我缺少ID_CAP_WEBBROWSERCOMPONENT功能,但我没有。这让我很困惑,直到我终于看了一眼文档:

在XAML中创建WebBrowser控件时,必须为该控件的p:System.Windows.FrameworkElement.Name属性指定一个值,以便Windows Phone功能检测工具能够正确检测并授予应用程序正确的功能。有关Windows Phone功能检测工具的更多信息,请参阅如何确定应用程序功能。

有了x:Name集,我终于可以有一次不崩溃的体验了。就我个人而言,这是有史以来最烦人的bug。这有助于我可以在商店上传测试版,尽管我没有支付任何开发费用,这是我以前不知道的。

TLDR:RTFM。

最新更新