Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Threading;
- namespace wenku8
- {
- class ContentView: ListBox
- {
- private String[] ps;
- // Number of paragraph to display
- private int displayLimit = 64;
- // Number of section splitted
- private int section;
- // Current section
- private int currentSection = 0;
- // Total Numbers of paragraphs
- private int l;
- public ContentView(String[] paragraphs)
- {
- ps = paragraphs;
- l = ps.Length;
- section = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(ps.Length / displayLimit)));
- initObjects();
- }
- public void NewContent(String[] paragraphs)
- {
- this.Items.Clear();
- ps = paragraphs;
- l = ps.Length;
- section = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(ps.Length / displayLimit)));
- currentSection = 0;
- initObjects();
- }
- private void initObjects()
- {
- addSection();
- }
- private void addSection()
- {
- int lineIndex = currentSection*displayLimit;
- ListBoxItem wrapper = null;
- for (int i = 0; i < displayLimit; i++)
- {
- if (lineIndex + i < l)
- {
- wrapper = new ListBoxItem();
- TextBlock p = new TextBlock();
- p.Text = ps[currentSection * displayLimit + i];
- p.TextWrapping = TextWrapping.Wrap;
- wrapper.Content = p;
- this.Items.Add(wrapper);
- }
- else
- {
- break;
- }
- }
- wrapper.Loaded += wrapper_Loaded;
- }
- void wrapper_Loaded(object sender, RoutedEventArgs e)
- {
- // This detects if the last item is loaded
- // so trigger the listbox to show more items
- if (currentSection < section)
- {
- currentSection++;
- addSection();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement