Pages

Monday, 11 March 2013

TextBox Control in WPF

TextBox Control In WPF



Setting Background and Foreground Colors

The Background and Foreground attributes set the background and foreground colors of text box. 


<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TextBox Width="200" Height="40" Canvas.Top="50" Canvas.Left="20"
        Background="Red" Foreground="Yellow">
            This is TextBox !!
        </TextBox>
    </Grid>
</Window>
 
Output-

Wrapping and Scrolling Text

The TextWrapping attributes sets the wrapping of text and VerticalScrollBarVisibility and HorizontalScrollBarVisibility sets the vertical and horizontal scroll bars visible.
TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility ="Visible"
 
Restricting Input Text

MaxHeight, MaxWidth, MaxLines, and MaxLength attributes of text box restricts the maximum height, maximum width, maximum number of lines, and maximum length of the text box. Similarly MinHeight, MinWidht, MinLines, and MinLength restricts the minimum height, minimum width, minimum number of lines, and minimum length of the text box. Setting IsReadOnly attribute to true makes the text box non editable.

1 comment: