我的Windows 8.1应用程序中有2页。他们两个都有一个共享按钮。
在第一页(即我的主页)上,共享按钮按假定的方式工作,即打开共享ui(如下所示)。
但是在共享ui打开应用程序后(有时在打开之前),我的其他页面(具有显示某些修改后的Web内容的Web View )就会崩溃。我在执行程序期间没有收到任何异常或错误。
当我使用Visual Studio将应用程序部署到手机上时,它不会崩溃,但是随后运行该应用程序(没有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中的“生命周期事件”选项卡(如this answer中的图片所示)。
问题可能还在于您导航到不可序列化的页面时传递了一些参数。在这种情况下,当应用程序被挂起时,SuspensionManager可能会引发异常。
关于c# - 打开共享ui后Windows Phone 8.1应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28961050/