RadControls for Silverlight

The purpose of this tutorial is to walk you through the common task of configuring RadMaskedTextBox for working with selection. The following "selection" features will be demonstrated:

SelectionOnFocus

The SelectionOnFocus property of RadMaskedTextBox allows you to specify what will happen with the cursor when the control gets focus. The values for the SelectionOnFocus property are predefined in the SelectionOnFocus enumeration:

  • If the SelectionOnFocus property is set to SelectAll, once the RadMaskedTextBox gets focused, it will select its whole text.
    CopyXAML
    <telerik:RadMaskedTextBox Mask="###-###-###" 
                              MaskType="Standard"
                              SelectionOnFocus="SelectAll" />
  • If the SelectionOnFocus property is set to CaretToBeginning, once the RadMaskedTextBox gets focused, the cursor will be positioned at the beginning.
    CopyXAML
    <telerik:RadMaskedTextBox Mask="###-###-###" 
                              MaskType="Standard"
                              SelectionOnFocus="CaretToBeginning" />
  • If the SelectionOnFocus property is set to CaretToEnd, once the RadMaskedTextBox gets focused, the cursor will be positioned at the end.
    CopyXAML
    <telerik:RadMaskedTextBox Mask="###-###-###" 
                              MaskType="Standard"
                              SelectionOnFocus="CaretToEnd" />
  • If the SelectionOnFocus property is set to Unchanged, once the RadMaskedTextBox gets focused, the position of the cursor won't be changed. This is the default value for the SelectionOnFocus property.

SelectionLength and SelectionStart

The SelectionStart property gets or sets the starting point of the selected text in the RadMaskedTextBox, while the SelectionLength gets or sets the number of characters selected in the RadMaskedTextBox. Both of the properties could be used in a combination with the GotFocus event, like in the example below:

CopyXAML
<telerik:RadMaskedTextBox x:Name="radMaskedTextBox" 
                          GotFocus="radMaskedTextBox_GotFocus"
                          Mask="###-###-###"
                          MaskType="Standard"
                          Value="123456789" />
CopyC#
private void radMaskedTextBox_GotFocus( object sender, RoutedEventArgs e )
{
    radMaskedTextBox.SelectionStart = 2;
    radMaskedTextBox.SelectionLength = 2;
}
CopyVB.NET
Private Sub radMaskedTextBox_GotFocus(sender As Object, e As RoutedEventArgs)
 radMaskedTextBox.SelectionStart = 2
 radMaskedTextBox.SelectionLength = 2
End Sub

See Also