0

在文档文件夹下面的代码中未显示选择文件。功能已正确设置(我认为),否则将引发异常。如果我设置了一个断点,我会看到代码到达了 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>
4

1 回答 1

2

这是因为您对 unsnap 的调用失败

尝试捕捉您的应用程序,然后它将按预期工作。删除退出功能部分,它按预期工作。

于 2012-12-20T20:06:03.040 回答