C# FileOpenPicker在Windows Phone 8.1应用程序中从磁贴而不是按钮启动时引发拒绝访问异常

C# FileOpenPicker在Windows Phone 8.1应用程序中从磁贴而不是按钮启动时引发拒绝访问异常,c#,windows-phone-8.1,fileopenpicker,C#,Windows Phone 8.1,Fileopenpicker,我试图通过在WindowsPhone8.1中从固定的磁贴启动FileOpenPicker API来使用它 磁贴中存储有一个命令,应用程序从该磁贴启动时将启动该命令的FileOpenPicker。在这种情况下,FileOpenPicker API抛出一个E_ACCESSDENIED异常。当从应用程序中的按钮调用相同的代码时,它不会崩溃。因此,为应用程序设置的功能是正常的,只是看起来FileOpenPicker调用的环境不一样 FileOpenPicker-openPicker=newfileope

我试图通过在WindowsPhone8.1中从固定的磁贴启动FileOpenPicker API来使用它

磁贴中存储有一个命令,应用程序从该磁贴启动时将启动该命令的FileOpenPicker。在这种情况下,FileOpenPicker API抛出一个E_ACCESSDENIED异常。当从应用程序中的按钮调用相同的代码时,它不会崩溃。因此,为应用程序设置的功能是正常的,只是看起来FileOpenPicker调用的环境不一样

FileOpenPicker-openPicker=newfileopenpicker();
openPicker.ViewMode=PickerViewMode.缩略图;
openPicker.SuggestedStartLocation=PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(“.jpg”);
openPicker.FileTypeFilter.Add(“.jpeg”);
openPicker.FileTypeFilter.Add(“.png”);
openPicker.PickSingleFileAndContinue();
最后一行是从平铺开始时崩溃的内容。这两种方案都在构建主页之后在主页内调用它。 磁贴从App.xaml.cs/OnLaunched()这样调用它:

if(!e.TileId.Equals(“应用”))
{
var mainPage=rootFrame.Content as Views.mainPage;
如果(主页!=null)
{
string命令=e.参数;
if(!string.IsNullOrWhiteSpace(command)和&command.Equals(Utils.TileCommand))
{
mainPage.TakePicture();
}
}
//否则
//{
//rootFrame.Navigate(typeof(Views.MainPage),e.Arguments);
//}
}
我还尝试了else部分(注释掉)并在MainPage.NavigatedTo()中调用TakePicture()方法,但情况也一样


有什么问题吗?

我不熟悉Windows Phone 8.1应用程序,但您的FileOpenPicker应该与UI线程异步运行

您是否尝试过按如下方式使用异步方法

FileOpenPicker openPicker = new FileOpenPicker(); 
openPicker.ViewMode = PickerViewMode.Thumbnail; 
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
openPicker.FileTypeFilter.Add(".jpg"); 
openPicker.FileTypeFilter.Add(".jpeg"); 
openPicker.FileTypeFilter.Add(".png"); 

StorageFile file = await openPicker.PickSingleFileAsync();

可能是rootFrame为null,或者它的内容为null。。检查OnLaunched方法中的根框架是否为null或内容是否为null。这可能是个问题。

谢谢您的输入,SebD,但是Studio说:“警告CS0618:'FileOpenPicker.PickSingleFileAsync()'已过时:'PickSingleFileAsync将不适用于Windows Phone 8.1。相反,请使用PickSingleFileAndContinue'。Rohit,根框架没有问题,在openPicker.PickSingleFileAndContinue()行上引发异常;。谢谢你的意见。