Scenario:

In this article i will use a FilePicker to upload image from any location in PC to my Application. Following is a screenshot of the application:

Steps to follow:

  1. Add a StackPanel with Image and button Control inside your MainPage.xaml file (in my case) and create a click event handler of your button. Following is the code:
     <grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <stackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                <image x:Name="MyImg" Source="Assets/Placeholder.PNG" Width="400" Height="400"/>
                <button VerticalAlignment="Center" HorizontalAlignment="Center" Content="Change Image" x:Name="changeImageBtn" Click="changeImageBtn_Click"/>
            </stackPanel>
        </grid>
    
  2.  Now open your MainPage.xaml.cs file and inside the changeImageBtn_Click function add the following code:

    FileOpenPicker openPicker = new FileOpenPicker();
                    openPicker.ViewMode = PickerViewMode.Thumbnail;
                    openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                    openPicker.FileTypeFilter.Add(".jpg");
                    openPicker.FileTypeFilter.Add(".jpeg");
                    openPicker.FileTypeFilter.Add(".png");
    
                    StorageFile file = await openPicker.PickSingleFileAsync();
                    if (file != null)
                    {
    
                        var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                        var image = new BitmapImage();
                        image.SetSource(stream);
    
                        MyImg.Source = image;
    
                    }
                    else
                    {
                        // "Operation cancelled."
                    }
    
    
  3. Now open your Package.appxmanifest file and move to declaration tabs, once you went there add a new declaration for FileOpenPicker from available declarations dropdown as shown below:
    That’s All.
    Happy Coding