0


I have a Printlayout, which is filled by DataBase-Values.
Everything works just well, except for two fields.

The Problem is, if the Text (string from DataBase) is to long for the TextBox, the TextBox cannot show the complete Text.
And the User cannot print the whole Text.

So I tried to put the TextBox into a ViewBox. But the ViewBox sacels the whole TextBox and not the Text. The result is, that some space is not used.

XAML:

<Viewbox StretchDirection="DownOnly" Width="430" Height="180" Grid.Column="1">
<TextBox x:Name="Tbx_Auftrag" Width="430" Height="auto" Margin="0,12,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="Wrap"/>
</Viewbox>

Result:

Image of Printview with ViewBox

Is it possible, that the FontSize sizes automatically to the TextBox without a ViewBox? And if yes, how can I handle it?

lazzzzor
  • 1
  • 1
  • What is original problem you are trying to solve? How to scale the string to fit the page? `TextBox` is particularly wrong control (should be `TextBlock`). *"TextBox cannot show the complete Text"* - that's well known and user expect to see scrollbars if text doesn't fit. Are you sure your idea with scaling font (down to which extent? 0.001 px is still ok?) is a good idea? – Sinatr Aug 27 '20 at 11:18
  • You would have to measure the current text and fit it by adjusting the font size. – BionicCode Aug 27 '20 at 11:31
  • This sounds similar to your problem: https://stackoverflow.com/questions/8726256/textbox-will-not-stretch-to-fill-viewbox – Rand Random Aug 27 '20 at 11:42
  • @Sinatr The user prints a form (UserControl, size of A4, one page). In this form is a TextBox/TextBlock (i tried with both). This TextBlock displays a text. And if the text is too long, the TextBlock cannot display the complete text. And because the TextBlock is in a form, a scrollbar is not a solution (because you would print the scrollbar). So the FontSize has to auto change between 12pt to 9pt. – lazzzzor Aug 27 '20 at 11:55
  • I suggest you to provide user with *report*. Report is different from screenshot (what you are doing) of the form (which is optimized presentation of data to edit them), since it's optimized for printing. – Sinatr Aug 27 '20 at 12:00
  • @Sinatr Yea I thought about that too. And it's a good alternative solution. But is it not possible to automate this process? – lazzzzor Aug 27 '20 at 12:12

0 Answers0