问题描述
对于 FileOpenPicker 类.
FileOpenPicker picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
StorageFile file = await picker.PickSingleFileAsync();
当我通过按钮触发它时,我从最后一行得到以下异常:
When I trigger it from a button I get the following exception from the last line:
我认为在这种用法中使用FileOpenPicker的想法是,我不需要询问用户访问权限或指定任何功能?
I thought the idea of the FileOpenPicker in this usage was that I didn't need to ask the user for access permissions or specify any capabilities?
推荐答案
我在调用PickSingleFileAsync()
之前设置了一个断点.事实证明,在边框内按下TextBlock时会触发两个轻击事件(两者都具有相同的轻击事件处理程序).
I set a breakpoint just before the call to PickSingleFileAsync()
. Turns out that two tapped events were being fired when pressing a TextBlock within a Border (both with the same Tapped event handler).
第一个调用按预期工作,但随后的调用导致UnauthorizedAccessException,并且将在显示选择器后立即发生.
The first call worked as expected, but subsequent call resulted in the UnauthorizedAccessException and would occur straight after the picker was displayed.
这篇关于FileOpenPicker PickSingleFileAsync引发UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!