DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

WPF Multiline Textbox Example

By Ashok Nalam on 17 Jan 2014 | Category: WPF | Tagged: textbox 
This snippet shows how to create WPF multiline textbox
  Discuss Add Comment   |  
Add rating Rate this resource   

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
  1. AcceptsReturn="True" {If false you can not press enter key}
  2. TextWrapping="Wrap" {If NoWrap then text keeps on going to right side in same row}
  3. 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:

WPF Multiline Textbox Demo

  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 7003  (Expert)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.