在下面的代码中,未显示文档文件夹以选择文件。功能已正确设置(我认为),否则将抛出异常。如果我设置了一个断点,我会看到代码到达await语句但是它就在那里并且没有任何反应。
Private Async Function Button_Click_1(sender As Object, e As RoutedEventArgs) As Task
If ApplicationView.TryUnsnap = False Then
StatusMessage = "Cannot unsnap."
Exit Function
End If
Dim filePicker As New FileOpenPicker
filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
filePicker.ViewMode = PickerViewMode.Thumbnail
filePicker.FileTypeFilter.Add(".pbn")
Dim pbnFile = Await filePicker.PickSingleFileAsync
If pbnFile IsNot Nothing Then
StatusMessage = pbnFile.Path
End If
End Function
编辑:上述方法中的第一行必须是:
If ApplicationView.Value = ApplicationViewState.Snapped AndAlso ApplicationView.TryUnsnap = False Then
问题解决了......
XAML:
<Page
x:Class="HandEditor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HandEditor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Click="Button_Click_1">Choose .pbn file</Button>
<TextBlock Grid.Row="1" Text="{Binding StatusMessage}"/>
</Grid>
</Page>