Choosing a file to open
In the previous examples, you have used files whose paths are defined directly in the code, either XAML or C#. However, sometimes it may be necessary to provide a user with the option of choosing a file to open. Of course, the suitable mechanism is available for UWP applications, as you will see in this recipe.
As an example, you will create a page with the Choose a file button. After clicking on it, the file picker will be presented, where a user can choose a particular file, restricting the options to .jpg
files. When the operation is confirmed, the image is loaded and presented in the user interface.
Getting ready
To step through this recipe, you only need the automatically generated project.
How to do it...
To prepare an example that allows to present an image chosen by the user, perform the following steps:
- Add the
Image
control (where the chosen photo will be shown) and the button to the page by adjusting the content of theMainPage.xaml
file, as follows:...