Skip to main content

How To: Create a PageView and Populate It with Data

  • 3 minutes to read

This example demonstrates how to create a Page View, bind it to data and use templates to visualize its items. The last section of this example contains the complete example code.

DXControls - PageView Example

Steps

  1. Start Visual Studio and create a new WPF project by selecting FILE | New | Project… in the main menu. In the invoked New Project window, select WPF Application, change the name to PageViewSample, and click OK.
  2. Change the main window’s theme to Office 2013. To do so, reference the DevExpress Core namespace and use the ThemeManager.

    using DevExpress.Xpf.Core;
    
    // ...
    
    public partial class App : Application 
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            ThemeManager.ApplicationThemeName = Theme.Office2013Name;
            base.OnStartup(e);
        }
    }
    
  3. Locate the PageView control in the Toolbox and drop it onto the form.

    <Grid>
        <dxwui:PageView />
    </Grid>
    
  4. Define the data source in XAML.

    <Window.DataContext>
         <local:EmployeesData/>
     </Window.DataContext>
    

    The EmployeesData class, which is used as a data source, is defined in the C# code. The code for this and other data source classes is listed later in this example.

  5. Now create two DataTemplate objects in the Resources section. These data templates will specify how items and their headers within the PageView should appear.

    <Window.Resources>
            <DataTemplate x:Key="ItemHeaderTemplate">
                <Grid>
                    <TextBlock Text="{Binding FirstName}"/>
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="ItemContentTemplate">
                <Grid x:Name="Grid_Content" Margin="100, 0, 100, 0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="White" BorderBrush="Black" BorderThickness="0" Margin="0">
                            <Image Margin="1" Source="{Binding Photo}" Stretch="None" />
                        </Border>
    
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding FullName}" TextWrapping="Wrap" Grid.Row="1" FontFamily="Times New Roman" FontSize="22.667" Foreground="#FF1059A3" Margin="0,15,0,5" />
                        <Grid Grid.Row="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Job Title:" Grid.Column="0" Grid.Row="0"/>
                            <TextBlock Text="City:" Grid.Column="0" Grid.Row="1"/>
                            <TextBlock Text="Country:" Grid.Column="0" Grid.Row="2"/>
                            <TextBlock Text="E-mail:" Grid.Column="0" Grid.Row="3"/>
                            <TextBlock Text="Birth Date:" Grid.Column="0" Grid.Row="4"/>
                            <TextBlock Text="Hire Date:" Grid.Column="0" Grid.Row="5"/>
                            <TextBlock Text="Martial Status:" Grid.Column="0" Grid.Row="6"/>
                            <TextBlock Text="{Binding JobTitle}" TextWrapping="Wrap"  Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="0"/>
                            <TextBlock Text="{Binding City}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="1"/>
                            <TextBlock Text="{Binding CountryRegionName}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="2"/>
                            <TextBlock Text="{Binding EmailAddress}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="3"/>
                            <TextBlock Text="{Binding BirthDate}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="4"/>
                            <TextBlock Text="{Binding HireDate}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="5"/>
                            <TextBlock Text="{Binding MaritalStatus}" TextWrapping="Wrap" Foreground="#FF1059A3" Margin="10,0" Grid.Column="1" Grid.Row="6"/>
                        </Grid>
                        <Grid Grid.Row="3" Margin="0,20,0,0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Rectangle Fill="#FFA4A7BD" StrokeThickness="0" Height="1" Margin="0" VerticalAlignment="Top" />
                            <TextBlock Margin="10" Grid.Row="1" TextWrapping="Wrap" Foreground="#FF3B3D60" Text="{Binding Phone}" />
                        </Grid>
                    </Grid>
                </Grid>
            </DataTemplate>
        </Window.Resources>
    
  6. Now you can assign the data templates to the PageView’s ItemTemplate and ContentTemplate properties.

    <dxwui:PageView Header="Page View" ItemTemplate="{StaticResource ItemHeaderTemplate}" ContentTemplate="{StaticResource ItemContentTemplate}"/>
    
  7. Finally, set a data source for the PageView via the ItemsSource property. You can also specify the AnimationType property to set animation effects used when an end-user navigates through pages.

    <dxwui:PageView AnimationType="SlideHorizontal" ItemsSource="{Binding DataSource}" Header="Page View" ItemTemplate="{StaticResource ItemHeaderTemplate}" ContentTemplate="{StaticResource ItemContentTemplate}"/>
    
  8. You can now launch the application to see the results. Remember to include the code for classes encapsulating the data source. This code can be found below. The .XML file that stores employee data is also listed later in this example. Include this file in your project and set its BuildAction property to EmbeddedResource.

Complete Code

This example demonstrates how to create a PageView, bind it to data and use templates to visualize its items and item headers.

View Example