Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using System.Windows.Threading;
  10.  
  11.  
  12. namespace wenku8
  13. {
  14.     class ContentView: ListBox
  15.     {
  16.         private String[] ps;
  17.         // Number of paragraph to display
  18.         private int displayLimit = 64;
  19.         // Number of section splitted
  20.         private int section;
  21.         // Current section
  22.         private int currentSection = 0;
  23.         // Total Numbers of paragraphs
  24.         private int l;
  25.  
  26.         public ContentView(String[] paragraphs)
  27.         {
  28.             ps = paragraphs;
  29.             l = ps.Length;
  30.             section = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(ps.Length / displayLimit)));
  31.            
  32.             initObjects();
  33.         }
  34.  
  35.         public void NewContent(String[] paragraphs)
  36.         {
  37.             this.Items.Clear();
  38.             ps = paragraphs;
  39.             l = ps.Length;
  40.             section = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(ps.Length / displayLimit)));
  41.             currentSection = 0;
  42.  
  43.             initObjects();
  44.         }
  45.  
  46.         private void initObjects()
  47.         {
  48.             addSection();
  49.         }
  50.  
  51.         private void addSection()
  52.         {
  53.             int lineIndex = currentSection*displayLimit;
  54.             ListBoxItem wrapper = null;
  55.             for (int i = 0; i < displayLimit; i++)
  56.             {
  57.                 if (lineIndex + i < l)
  58.                 {
  59.                     wrapper = new ListBoxItem();
  60.                     TextBlock p = new TextBlock();
  61.                     p.Text = ps[currentSection * displayLimit + i];
  62.                     p.TextWrapping = TextWrapping.Wrap;
  63.                     wrapper.Content = p;
  64.                     this.Items.Add(wrapper);
  65.                 }
  66.                 else
  67.                 {
  68.                     break;
  69.                 }
  70.             }
  71.             wrapper.Loaded += wrapper_Loaded;
  72.         }
  73.  
  74.         void wrapper_Loaded(object sender, RoutedEventArgs e)
  75.         {
  76.             // This detects if the last item is loaded
  77.             // so trigger the listbox to show more items
  78.             if (currentSection < section)
  79.             {
  80.                 currentSection++;
  81.                 addSection();
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement