The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
Using PickSingleFileAndContinue to load an image and crop it - Windows Phone 8.1 RRS feed

  • Question

  • Hi,

    I'm a little confused at how to use the PickSingleFileAndContinue method in app development for Windows Phone 8.1. Previously, you could just use PickSingleFileAsync to select a file, but this won't be available in Windows Phone 8.1. So, how using Visual Basic can I have the user select an image from their library, allow them to crop it, bring the image into the app and set it as an image source all in a button click event?

    Thanks, Brendon.


    Monday, August 4, 2014 7:17 PM

Answers

  • Hi,

    That is to avoid the memory issue caused by the async method when phone memory is low. You can refer to this blog for more info: http://blogs.msdn.com/b/thunbrynt/archive/2014/04/16/windows-phone-8-1-for-developers-contracts.aspx and find the example about how to use the PickSingleFileAndContinue method now.

    To save your time, I just converted the c# code to vb.net:

    In App.xaml.vb:

        Protected Overrides Sub OnActivated(args As IActivatedEventArgs)
            Dim root = TryCast(Window.Current.Content, Frame)
            Dim mainPage = TryCast(root.Content, MainPage)
            If mainPage IsNot Nothing AndAlso TypeOf args Is FileOpenPickerContinuationEventArgs Then
                mainPage.ContinueFileOpenPicker(TryCast(args, FileOpenPickerContinuationEventArgs))
            End If
        End Sub

    In mainpage.xaml.vb:

        Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
            Dim openPicker = New FileOpenPicker() With
                             {
                                 .ViewMode = PickerViewMode.Thumbnail,
                                 .SuggestedStartLocation = PickerLocationId.PicturesLibrary
                                 }
    
            openPicker.FileTypeFilter.Add(".jpg")
            openPicker.PickSingleFileAndContinue()
    
        End Sub
    
        Public Sub ContinueFileOpenPicker(fileOpenPickerContinuationEventArgs As FileOpenPickerContinuationEventArgs)
    
            If fileOpenPickerContinuationEventArgs.Files IsNot Nothing Then
                ' Do something with selected file/s
            End If
        End Sub

    Thanks,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Stupidentist Tuesday, August 5, 2014 2:01 PM
    Tuesday, August 5, 2014 5:52 AM
    Moderator

All replies

  • Hi,

    That is to avoid the memory issue caused by the async method when phone memory is low. You can refer to this blog for more info: http://blogs.msdn.com/b/thunbrynt/archive/2014/04/16/windows-phone-8-1-for-developers-contracts.aspx and find the example about how to use the PickSingleFileAndContinue method now.

    To save your time, I just converted the c# code to vb.net:

    In App.xaml.vb:

        Protected Overrides Sub OnActivated(args As IActivatedEventArgs)
            Dim root = TryCast(Window.Current.Content, Frame)
            Dim mainPage = TryCast(root.Content, MainPage)
            If mainPage IsNot Nothing AndAlso TypeOf args Is FileOpenPickerContinuationEventArgs Then
                mainPage.ContinueFileOpenPicker(TryCast(args, FileOpenPickerContinuationEventArgs))
            End If
        End Sub

    In mainpage.xaml.vb:

        Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
            Dim openPicker = New FileOpenPicker() With
                             {
                                 .ViewMode = PickerViewMode.Thumbnail,
                                 .SuggestedStartLocation = PickerLocationId.PicturesLibrary
                                 }
    
            openPicker.FileTypeFilter.Add(".jpg")
            openPicker.PickSingleFileAndContinue()
    
        End Sub
    
        Public Sub ContinueFileOpenPicker(fileOpenPickerContinuationEventArgs As FileOpenPickerContinuationEventArgs)
    
            If fileOpenPickerContinuationEventArgs.Files IsNot Nothing Then
                ' Do something with selected file/s
            End If
        End Sub

    Thanks,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Stupidentist Tuesday, August 5, 2014 2:01 PM
    Tuesday, August 5, 2014 5:52 AM
    Moderator
  • Hi Alan,

    That's exactly what I was looking for. Thanks for your help!

    Tuesday, August 5, 2014 2:01 PM