TextBox Selection Model in Silverlight 4


Introduction

In this article we will see the Text Selection Model in Silverlight 4.

Create Silverlight Application

Fire up Visual Studio 2010 and create a Silverlight Application and name the solution as TextSelection Model.

TextSel1.gif

Let's have the following design which would help us understand the TextBox Selection model.

TextSel2.gif

As you see in above image the selection operation's would be executed if any by the Execute Button. And the result would be displayed in the below textbox.

We will discuss several properties of the model.

Selection Background and Selection Foreground

These properties affect how the selection area would be displayed.

TextSel3.gif

As you see in above image, the defalut is White in Black.

Let's change it.

TextSel4.gif

The following is the selection area style if changed as above.

TextSel5.gif

Selected Text

This property is used to get or set the selected text in a Textbox.

Let's see how we can use the property.

TextSel6.gif

And the result is:

TextSel7.gif

Selection Start and Selection Length

As the properties names are, Selection Start position would give the position and Selection Length would give the length of the selection.

Let's just add the properties output to the above example.

TextSel8.gif


And the result is :

TextSel9.gif

Hope this article helps.
 

Up Next
    Ebook Download
    View all
    Learn
    View all