2012-12-20 50 views
0

在下面的代碼文件夾中沒有顯示選擇一個文件。功能設置正確(我認爲),否則會引發異常。如果我設置了一個斷點,我就會看到代碼到達了await語句,但它仍然在那裏,沒有任何反應。爲什麼在Windows應用商店應用程序中未打開「文檔」文件夾?

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> 

回答

2

這是因爲你的call to unsnap is failing

嘗試捕捉您的應用程序,然後它會按預期工作。刪除退出功能部分,並按預期工作。

相關問題