views:

402

answers:

0

I was wondering if the method for paging shown in this blog the only way to accomplish paging using ItemsControl in SilverLight 3?

Dynamic Paging in Silverlight

I want to display the following:

HeaderText 1
Sub Item 1
Sub Item 2
HeaderText 2
Sub Item 3
Sub Item 4

PREVIOUS FORWARD

Here is what I have so far.

MainPage.xaml

<ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" BorderThickness="1">
   <ItemsControl x:Name="SearchResults" Margin="0,8,0,0" Grid.Row="1">
     <ItemsControl.ItemTemplate>
        <DataTemplate>
          <Grid Margin="0,6,0,0" ShowGridLines="True">
            <Grid.RowDefinitions>
             <RowDefinition Height="Auto" />
             <RowDefinition Height="Auto" />
             <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="100"></ColumnDefinition>
              <ColumnDefinition Width="100"></ColumnDefinition>
              <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
           <TextBlock x:Name="Header" Text="{Binding Path=HeaderText, Mode=OneWay}" Grid.ColumnSpan="3" TextWrapping="Wrap" Foreground="White" />
           <TextBlock Text="SubItem" Grid.Row="1"  />
           <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" Grid.ColumnSpan="3">
              <Button Content="Clear" Width="80" Height="22" />
           </StackPanel>                                
         </Grid>
       </DataTemplate>
     </ItemsControl.ItemTemplate>                    
   </ItemsControl>
 </ScrollViewer>

MainPage.xaml.cs

public partial class MainPage : UserControl
{
  ObservableCollection<HeaderText> searchResults = new ObservableCollection<HeaderText>();
    PagedCollectionView pcv;

public MainPage()
    {
        InitializeComponent();

        Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        LoadData();
    }

    private void LoadData()
    {
        for (int i = 0; i < 100; i++)
        {
            HeaderText q = new HeaderText();
            string qText = "HeaderText" + (i + 1).ToString();
            searchResults.Add(new HeaderText() { Header= qText });
        }

        pcv = new PagedCollectionView(searchResults);
        SearchResults.ItemsSource = pcv;
    }
}
public class HeaderText
{
    public string Header{ get; set; }
    public IList<SubItem> SubItems{ get; set; }
}

public class SubItem
{
    public string SubItemText{ get; set; }
}