WPF and Silverlight Edition Basic Library / ListBox / ListBox Quick Start
ListBox Quick Start

The following quick start guide is intended to get you up and running with the C1ListBox control. In this quick start you'll start in Visual Studio and create a new project, add C1ListBox to your application, and customize the appearance and behavior of the control.

In this step, you'll create a WPF or Silverlight application in Visual Studio using ListBox for WPF and Silverlight.

Complete the following steps:

  1. In Visual Studio, select File | New Project.
  2. In the New Project dialog box, select either Windows Desktop or Silverlight from the Templates in the left-hand pane.
    New Project Dialog Box

    New Project Dialog Box

  3. Select WPF Application or Silverlight Application, depending on the template you chose. 
  4. Enter a Name for your project, for example "QuickStart", and click OK. In a WPF Application, the MainWindow.xaml file will open.
    1. If you selected a Silverlight Application, when you click OK, the New Silverlight Application dialog box will appear.
    2. Click OK to accept default settings. This will close the New Silverlight Application dialog box and create your project.
    3. The MainPage.xaml file should open.
  5. Add the following assemblies to your application by right-clicking the References folder and selecting Add Reference:
    • WPF: C1.WPF.4.dll
    • Silverlight: C1.Silverlight.5.dll
  6. Add the following <StackPanel> markup between the <Grid> and </Grid> tags to add a StackPanel containing a TextBlock and ProgressBar:
    XAML
    Copy Code
    <StackPanel x:Name="loading" VerticalAlignment="Center">
        <TextBlock Text="Retrieving data from Flickr..." TextAlignment="Center"/>
        <ProgressBar IsIndeterminate="True" Width="200"  Height="4"/>
    </StackPanel>
    
  7. Navigate to the Toolbox and double-click the C1ListBox icon to add the control to the grid. This will add the reference and XAML namespace automatically.
  8. Edit the  <c1:C1ListBox> tag to customize the control:
    XAML
    Copy Code
    <c1:C1ListBox x:Name="listBox" ItemsSource="{Binding}" Background="Transparent" Visibility="Collapsed" ItemWidth="800" ItemHeight="600" Zoom="Fill" ViewportGap="0" RefreshWhileScrolling="False"></c1:C1ListBox>
    
    This gives the control a name and customizes the binding, background, visibility, size, and refreshing ability of the control.
  9. Add the following markup between the <c1:C1ListBox> and </c1:C1ListBox> tags:
    XAML
    Copy Code
    <c1:C1ListBox.PreviewItemTemplate>
        <DataTemplate>
            <Grid Background="Gray">
                <Image Source="{Binding Thumbnail}" Stretch="UniformToFill"/>
            </Grid>
        </DataTemplate>
    </c1:C1ListBox.PreviewItemTemplate>
    <c1:C1ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Image Source="{Binding Content}" Stretch="UniformToFill"/>
                <TextBlock Text="{Binding Title}" Foreground="White" Margin="4 0 0 4" VerticalAlignment="Bottom"/>
            </Grid>
        </DataTemplate>
    </c1:C1ListBox.ItemTemplate>
    
    This markup adds data templates for the C1ListBox control's content. Note that you'll complete binding the control in code.