Sat down, thought. But everything turns out to be simple. Why did I climb into the jungle? Maybe I wanted to find a ready-made solution ... And it turned out to be redundant. Although it still needs to be checked, it may not all be in vain ... Actually, this is what occurred to me now about self-made paging: XAML:
<Window x:Class="WpfApplication3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="7*"></RowDefinition> <RowDefinition Height="1*"></RowDefinition> </Grid.RowDefinitions> <ListView Name="lvList" Grid.Row="0" ItemsSource="{Binding MyItems}"/> <TextBox Name="tbPage" Grid.Row="1" HorizontalAlignment="Left" Width="517" TextChanged="tbPage_TextChanged"/> </Grid> </Window>
Codebehind:
public partial class MainWindow : Window { System.Collections.ObjectModel.ObservableCollection<string> collection; List<string> items; int pageLength = 50; public MainWindow() { InitializeComponent(); // инициализировали коллекцию items = new List<string>(); for (int i=0; i< 10000; i++) { items.Add("Строка номер " + i); } ChangePage(0); } public void ChangePage(int pageNum) { List<string> result = new List<string>(); result = new List<string>(items.Skip(pageNum * pageLength)); result = new List<string>(result.Take(pageLength)); collection = new System.Collections.ObjectModel.ObservableCollection<string>(result); lvList.ItemsSource = collection; } private void tbPage_TextChanged(object sender, TextChangedEventArgs e) { int page = 1; if (Int32.TryParse(tbPage.Text, out page)) { ChangePage(page); } } }
Only it is necessary to rewrite all the application logic, if you do this. What do you think?