Text Insert in TextBox In Silverlight 3


There are various requirements for the TextBox Text input. In this article we will see how can we insert text in any TextBox Caret position.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as TextInsert.


Here is the Idea, there will be a list of Text in a combo box and we need to add the selected Text from the ComboBox to the carat position of TextBox.

Open the Solution and design the above.

Now insert some text to the ComboBox in the application load.

public MainPage()



List<string> myList = new


“[UserName]”,“[Sender]”, “[UserContact]”, “[UserAddress]”


cmbTexts.ItemsSource = myList;


Now create an event handle of ComboBox SelectionChanged.


Add the following code into the above handler.

void cmbTexts_SelectionChanged(object sender, SelectionChangedEventArgs e)


string selected = txtMyTextBox.Text;

int positionNotificationTemplate = txtMyTextBox.SelectionStart;

string strTemp1 = cmbTexts.SelectedItem.ToString();

selected = selected.Insert(positionNotificationTemplate, strTemp1);

txtMyTextBox.Text = selected;


Now run the application and write your message in TextBox.

Hope this article is helpful.