Introduction
In Windows Forms, it's easier to set TextBox control as multiline by setting MultiLine="True". But with WPF, you will not find multiline property for TextBox control. So in order to make WPF textbox as multline set below 3 properties
- AcceptsReturn="True" {If false you can not press enter key}
- TextWrapping="Wrap" {If NoWrap then text keeps on going to right side in same row}
- VerticalScrollBarVisibility="Visible" {If property is not set you have to use up/down keys or mouse wheel to see content}
Texbox Code
<TextBox AcceptsReturn="True" TextWrapping="NoWrap" VerticalScrollBarVisibility="Visible"/>
Example:
<Window x:Class="DotNetMirror.WPFMultiLineTBWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Demo : Multiline Textbox in WPF" Height="300" Width="300">
<StackPanel Orientation="Vertical">
<Label Content="Multiline Textbox in WPF"></Label>
<TextBox Height="200" Name="tbmlName" AcceptsReturn="True" TextWrapping="NoWrap" VerticalScrollBarVisibility="Visible"/>
</StackPanel>
</Window>
Output: