WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
TextBox Control In WPF Web Base
Previous Home Next
Setting Background and Foreground Colors

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

<Page x:Class="WpfBrowserApplication2.Page4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page4" Height="318" Width="391">
<Grid Background="LightCyan" Height="297" Width="343">
<TextBox Canvas.Top="50" Canvas.Left="20" Background="Coral"
Margin="126,134,54,0" Height="28" VerticalAlignment="Top"
Name="textBox1">
</TextBox>
<Label Height="28" Margin="12,68,0,0" Name="label1"
       VerticalAlignment="Top" HorizontalAlignment="Left"
	   Width="78">Name:</Label>
<TextBox Height="23" Margin="126,68,54,0" Name="textBox2"
		 VerticalAlignment="Top" />
<TextBox Height="23" Margin="126,103,54,0" Name="textBox3" 
		 VerticalAlignment="Top" />
<Label Height="28" HorizontalAlignment="Left" Margin="12,103,0,0"
	   Name="label2" VerticalAlignment="Top" Width="86"> 
	   Father Name:</Label>
<Label HorizontalAlignment="Left" Margin="12,134,0,132"
	   Name="label3" Width="56">City:</Label>
<Button Height="22" Margin="97,0,128,91" Name="button1"
	    VerticalAlignment="Bottom" Click="button1_Click">
		Button</Button>
<Label Height="28" Margin="20,0,171,53" Name="label4"
		VerticalAlignment="Bottom">Label</Label>
<Label Height="28" Margin="20,0,171,27" Name="label5" 
		VerticalAlignment="Bottom">Label</Label>
<Label Height="28" Margin="20,0,161,0" Name="label6"
		VerticalAlignment="Bottom">Label</Label>
</Grid>
</Page>

.CS Code:

private void button1_Click(object sender, RoutedEventArgs e)
{
label4.Content = "Welcome Mr." + textBox2.Text;
label5.Content = "Father Name::" + textBox3.Text;
label6.Content = "City::" + textBox1.Text;
}
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"

Non Editable TextBox

The IsReadOnly property of the TextBox sets the text box read only. By default, it is false.

 IsReadOnly="True" 

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.

Spell Checking

Spell checking can be enabled on the text box control by setting the SpellCheck.IsEnabled to true. When you set the SpellChek.IsEnabed to true then text box control will automatically detect the wrong word and underlined these words with red line as see in the Image 2, the similar kind of behavior you have seen while typing in the Microsoft Word.

Now as you have experience it in Microsoft Word that you can right click on the red underlined word and it will give you suggestions of the word in list box. From the list of the suggested option for the wrong word you can choose the correct word.

In the Image you can see that I have entered wrong words like wrog entere and TextBox. You can place mouse on any of the word and select the correct word from the suggestion which are appears by right clicking on the word

It Has A Real Undo Stack

Have you ever written code that manually called the Undomethod of the TextBox control, and been disappointed with the results. Spoilers follow for those who have not tried this: it only keeps track of the last state of the text. Since the advent of Adobe Photoshop* in the late middle ages, people have grown accustomed to programs being able to undo as many actions as they have done.

Well with the WPF TextBox control that functionality is built-in. If you find implementing a custom Undo Stack fun, then cling tightly to the WinForms TextBox, if you would rather forego that task so that you can focus on a more important problems continue reading.

What code do you need to get it working? Check it out:

wpfTextBox.IsUndoEnabled = true;
wpfTextBox.UndoLimit = 1024;

Oh yeah, and whereas the System.Windows.Forms.TextBox control has an Undo method, the WPF equivalent supports this beautiful couple:

wpfTextBox.Undo();
wpfTextBox.Redo();

Just be sure to never include those two lines of code one right after another like that.

Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF