I have FixedDocument
page and I want to place TextBlock
on it, but it can be that Textblock
doesn't fit on page by height.
So I want to take lines from generated TextBlock
with TextWrapping
, and then create new TextBlock
, that fitted by height and place it on page.
TextBlock
have LineCount
private property, that mean that it has TextLines
after wrapping and I can somehow get it.
Creating TextBlock
with runs:
public TextItem(PageType pageType, Run[] runs, Typeface typeFace, double fontSize)
: base(pageType)
{
this.TextBlock = new TextBlock();
this.TextBlock.Inlines.AddRange(runs);
if (typeFace != null)
this.TextBlock.FontFamily = typeFace.FontFamily;
if (fontSize > 0)
this.TextBlock.FontSize = fontSize;
this.TextBlock.TextWrapping = TextWrapping.Wrap; //wrapping
}
Creating TextBlock
with text:
public TextItem(PageType pageType, String text, Typeface typeFace, double fontSize)
: base(pageType)
{
if (typeFace == null || fontSize == 0)
throw new Exception("Wrong textitem parameters");
this.TextBlock = new TextBlock();
this.TextBlock.Text = text;
this.TextBlock.FontFamily = typeFace.FontFamily;
this.TextBlock.FontSize = fontSize;
this.TextBlock.TextWrapping = TextWrapping.Wrap;
this.TextBlock.TextAlignment = TextAlignment.Justify;
this.TypeFace = typeFace;
}
Set width to TextBlock
and get DesiredSize
:
this.TextBlock.Width = document.CurrentPage.Content.ActualWidth;
this.TextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
FlowDocument
? A link to msdn. – Dribblem try layout elements manual on single FixedPage, that have A4 size. That
s why i need to split textblock if it does not fit. – Kermanshah