Windows phone 8.1 应用程序在打开共享后立即崩溃 ui

Windows phone 8.1 application crashing just after opening share ui

我的 windows 8.1 应用程序中有 2 个页面。他们都有一个共享按钮。 在我主页的第一页上,共享按钮按预期工作,即打开共享 ui(如下所示)。

但是在我的另一个页面(它有一个用于显示一些修改过的网页内容的网络视图)上,一旦共享 ui 打开应用程序崩溃(有时在打开之前)。我在程序执行期间没有收到任何异常或错误。

当我使用 Visual Studio 将应用程序部署到我的 phone 时,它不会崩溃,但在 运行 之后(没有 visual studio)应用程序开始崩溃。

这显示了我如何打开共享 UI (Find Full Code for the page here)

try
{
   Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
}
catch(Exception ex)
{
   //Code to handle exception
}

这是编译时的部分输出(find full output here)

The thread 0x9ac has exited with code 259 (0x103).
The thread 0xca4 has exited with code 0 (0x0).
The thread 0xa80 has exited with code 259 (0x103).
The thread 0xc80 has exited with code 259 (0x103).
The thread 0xc44 has exited with code 259 (0x103).
The thread 0xcd8 has exited with code 259 (0x103).
The thread 0x8ec has exited with code 259 (0x103).
The thread 0xbac has exited with code 0 (0x0).
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll
The program '[2308] DATAPACKAGEHOST.EXE' has exited with code 1 (0x1).
The program '[1952] DATAPACKAGEHOST.EXE' has exited with code 1 (0x1).
The thread 0xc34 has exited with code 259 (0x103).
The thread 0xc78 has exited with code 259 (0x103).

Xaml 页面代码

    <Grid.RowDefinitions>

        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <!-- Page title -->

    <ProgressBar 
        Width="400" 
        Height="40" 
        Foreground="Black" 
        VerticalAlignment="Top" 
        IsIndeterminate="True" 
        Grid.Row="0"
        Canvas.ZIndex="10" 
        x:Name="Progress_content"        
        Visibility="Collapsed"/>
    <Grid x:Name="grid" Grid.Row="0" 
              VerticalAlignment="Top" 
              Visibility="Collapsed"
              Background="{StaticResource HeadingBackground }" 
              Canvas.ZIndex="1">
        <TextBlock Text="Data could not be updated at the moment" 
                x:Name="Update_Error"
                Margin="15,0"
                Height="0"
                VerticalAlignment="Center"
                FontSize="15"
                Visibility="Collapsed"
                Foreground="White" 
                TextWrapping="WrapWholeWords"
                FontFamily="{StaticResource TextBlockFontFamily}" Canvas.ZIndex="1"/>
    </Grid>
    <WebView Grid.Row="0" NavigationStarting="Browser_NavigationStarting" 
             x:Name="in_app_browser" 
             NavigationCompleted="Browser_NavigationCompleted"
             NavigationFailed="Browser_NavigationFailed" 
             LoadCompleted="Nav_Complete" GotFocus="Hide_Error"/>
    <ad:AdControl 
            x:Name="adDuplexAd" 
            AdUnitId="122875"
            AppKey="ed3d918f-ba50-4702-a5eb-a12cad42b9de" 
            Grid.Row="1"
            />
</Grid>

<Page.BottomAppBar>

    <CommandBar Background="{StaticResource AppBarBackground}" >
        <AppBarButton x:Name="Refresh" Label="Refresh" Click="Refresh_Posts" Icon="Refresh"/>

        <AppBarButton x:Name="Share" Label="Like" Click="Share_Click">
            <AppBarButton.Icon>
                <BitmapIcon UriSource="ms-appx:///Assets/Share.png" Height="20" Width="20"/>
            </AppBarButton.Icon>
        </AppBarButton>

        <CommandBar.SecondaryCommands>
            <AppBarButton x:Uid="AboutButton" Label="about" Click="AboutPage"/>

        </CommandBar.SecondaryCommands>

    </CommandBar>

</Page.BottomAppBar>

有什么问题?

挂起可能有问题(调试时没有调用)。

如果您尝试调试挂起事件,最好的办法是使用 VS 中的 Lifecycle events 选项卡(如 this answer 中的图片所示)。

问题还可能是您在导航到不可序列化的页面时传递了一些参数。在这种情况下,当应用程序被挂起时,SuspensionManager 可能会抛出异常。