2014-07-13 24 views
2

我想在Windows Phone的8.1.I通過文件選擇器選擇了一個圖像workk使用此代碼工作與圖像中的Windows Phone通過文件選取回升8.1

private async void gallery_Tapped(object sender, TappedRoutedEventArgs e) 
    { 
     FileOpenPicker openPicker = new FileOpenPicker(); 
     openPicker.ViewMode = PickerViewMode.Thumbnail; 
     openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
     openPicker.FileTypeFilter.Add(".jpg"); 
     openPicker.FileTypeFilter.Add(".jpeg"); 
     openPicker.FileTypeFilter.Add(".png"); 

     // Launch file open picker and caller app is suspended and may be terminated if required 
     openPicker.PickSingleFileAndContinue(); 
    } 


public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) 
     { 
      if (args.Files.Count > 0) 
      { 
       StorageFile file=args.Files[0]; 

       IRandomAccessStream fileStream = await      file.OpenAsync(Windows.Storage.FileAccessMode.Read); 
       BitmapImage bitmapImage = new BitmapImage(); 

       bitmapImage.SetSource(fileStream); 
       MyImage.Source=bitmapImage; 

    } 
      else 
      { 

      } 
} 
選擇了一個圖像

ContinueFileOpenPicker不執行我試過this但無法理解that.Can任何蒞臨指導我一步一步我應該怎麼做,使之work.Thanks

+0

嘛阿爾季cle你鏈接包含一步一步的指導。看起來你不會在應用程序恢復時隨時隨地調用延續代碼。 – Stilgar

+0

可以ü發佈一些代碼 –

+1

您鏈接的文章不僅包含代碼,但有一個鏈接到一個完整的示例應用程序。 – Stilgar

回答

4
protected override void OnActivated(IActivatedEventArgs args) 
     { 
      var root = Window.Current.Content as Frame; 
      var mainPage = root.Content as MainPage; 
      if (mainPage != null && args is FileOpenPickerContinuationEventArgs) 
      { 
       mainPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs); 
      } 
     } 

將這個代碼app.xaml.cs它會運行

+0

它適合我。謝謝!解決方案簡單 – sahap

相關問題