The following quick start guide is intended to get you up and running with FilePicker for WPF. In this quick start, you'll create a new Visual Studio project with the C1FilePicker control to select image files and display them in another control.
XAML |
Copy Code
|
---|---|
<Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> |
XAML |
Copy Code
|
---|---|
<c1:C1FilePicker x:Name="C1FilePicker1" SelectedFilesChanged="C1FilePicker_SelectedFilesChanged" Grid.Row="0" Margin="15" Height="30" /> |
XAML |
Copy Code
|
---|---|
<ScrollViewer Grid.Row="1" Margin="15,0,15,0"> <ListBox x:Name="ListBox" /> </ScrollViewer> <StackPanel Grid.Row="2" Name="stackPanel1" Orientation="Horizontal" HorizontalAlignment="Center"> <Button Content="Clear File Selection" Name="button1" Click="button1_Click" Height="30" Margin="0,15,15,15" Width="150" Grid.Row="2" /> <Button Content="Clear List Items" Name="button2" Click="button2_Click" Height="30" Margin="15,15,0,15" Width="150" Grid.Row="2" /> </StackPanel> |
In the last step you set up a WPF application, but it currently does not function. In this step you'll continue by adding code to add functionality to the application.
Complete the following steps:
Visual Basic Copy Code Imports System.Windows.Media.Imaging Imports C1.WPF.Input
C# Copy Code using System.Windows.Media.Imaging; using C1.WPF.Input;
Visual Basic Copy Code Private Sub C1FilePicker_SelectedFilesChanged(sender As Object, e As EventArgs) If C1FilePicker1.SelectedFile IsNot Nothing Then Dim stream = C1FilePicker1.SelectedFile.OpenRead() Dim source = New BitmapImage() source.SetSource(stream) Dim image = New Image() image.Source = source image.Stretch = Stretch.Uniform image.Height = 100 ListBox.Items.Add(image) End If End Sub
C# Copy Code private void C1FilePicker_SelectedFilesChanged(object sender, EventArgs e) { if (C1FilePicker1.SelectedFile != null) { var stream = C1FilePicker1.SelectedFile.OpenRead(); var source = new BitmapImage(); source.SetSource(stream); var image = new Image(); image.Source = source; image.Stretch = Stretch.Uniform; image.Height = 100; ListBox.Items.Add(image); } }This code handles the SelectedFilesChanged event. When a user selects an image with the C1FilePicker control, the image is customized and added to the ListBox control.
Visual Basic Copy Code Private Sub button1_Click(sender As Object, e As RoutedEventArgs) C1FilePicker1.ClearSelection() End Sub Private Sub button2_Click(sender As Object, e As RoutedEventArgs) ListBox.Items.Clear() End Sub
C# Copy Code private void button1_Click(object sender, RoutedEventArgs e) { C1FilePicker1.ClearSelection(); } private void button2_Click(object sender, RoutedEventArgs e) { ListBox.Items.Clear(); }
Now that you've created a WPF application, set up the application, and added code to add functionality to the application, the only thing left to do is run your application. To observe your application's run-time interactions, complete the following steps:
What You've Accomplished
Congratulations, you've completed the FilePicker for WPF quick start! You've created a simple application that uses FilePicker for WPF to select image files that are then displayed in another control.