I would like to make a WPF text box which is big enough to show 3 lines of text. So far, I have this code:
System.Windows.Controls.TextBox myTextbox = new TextBox()
{
AcceptsReturn = true,
MinLines = 3,
MaxLines = 3,
TextWrapping = TextWrapping.Wrap,
FontFamily = new FontFamily("Microsoft Sans Serif"),
FontSize = 11,
};
However, when myTextBox is laid out there is no guarantee that it gets enough height to show 3 lines of text. Ideally, I would like to specify the FontSize to be “so small that myTextBox has room for 3 lines of text, and no smaller”. Is there a way to do this?
Well, I ended up simply putting the
TextBoxinto aScrollViewer, like this: