Advertisement
Guest User

Get strings from TextBlock

a guest
Jan 16th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. this.TextBlock.Width = document.CurrentPage.Content.ActualWidth;
  2. this.TextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  3.  
  4. Window w = new Window();
  5. w.Content = this.TextBlock;
  6. w.Show();
  7.  
  8. Drawing textBlockDrawing = VisualTreeHelper.GetDrawing(this.TextBlock);
  9. List<String> list = new List<String>();
  10. WalkDrawingForText(list, textBlockDrawing);
  11.  
  12. private static void WalkDrawingForText(List<String> list, Drawing d)
  13. {
  14.     var glyphs = d as GlyphRunDrawing;
  15.     if (glyphs != null)
  16.     {
  17.         list.Add(new string(glyphs.GlyphRun.Characters.ToArray()));
  18.     }
  19.     else
  20.     {
  21.         var g = d as DrawingGroup;
  22.         if (g != null)
  23.         {
  24.             foreach (Drawing child in g.Children)
  25.             {
  26.                 WalkDrawingForText(sb, child);
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement