Using the common dialog boxes
Windows has its own built-in dialog boxes for common operations, such as opening files, saving a file, and printing. Using these dialogs is very intuitive from the user's perspective, because she has probably used those dialogs before in other applications. WPF wraps some of these (native) dialogs. In this recipe, we'll see how to use some of the common dialogs.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple image viewer that uses the Open common dialog box to allow the user to select an image file to view:
Create a new WPF Application named
CH05.CommonDialogs
.Open
MainWindow.xaml
. Add the following markup to the existingGrid
:<Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition /> </Grid.RowDefinitions> <Button Content="Open Image" FontSize="20" Click="OnOpenImage" HorizontalAlignment="Center" Margin="4" /> <Image Grid.Row="1" x:Name="_img" Stretch=...