Won't Fix
Last Updated: 13 May 2016 12:47 by ADMIN
ADMIN
Telerik Admin
Created on: 05 Feb 2013 14:38
Category: WatermarkTextBox
Type: Bug Report
5
When click on the text in WatermarkTextBox it is not selected every time
When click with mouse on the text it is selected every second time even when SelectionOnFocus is set to "SelectAll". If you click before the text it is selected every time.
1 comment
ADMIN
Nasko
Posted on: 13 May 2016 12:47
Hi,

The observed issue is caused by the native WPF TextBox that is inherited by the RadWatermarkTextBox. The SelectAll method gets called when the control gets the focus. However, the native TextBox internally handles the MouseDown event - the logic implemented inside the MouseDown event places the caret at the location where the user has clicked. Because of that the control selects the Text when ti is focused and after the cursor is placed the selection vanishes.  

As a workaround you need to handle the PreviewLeftMouseButtonDown event of RadWatermarkTextBox. Inside it to check if the SelectionOnFocus property is set to SelectAll and if so to handle the event and Focus the control. By doing so the text will be selected as expected:

private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
	var waterMarkTextBox = sender as RadWatermarkTextBox;
	if(waterMarkTextBox != null && waterMarkTextBox.SelectionOnFocus == SelectionOnFocus.SelectAll
		&& !waterMarkTextBox.IsKeyboardFocusWithin)
	{
		e.Handled = true;
		waterMarkTextBox.Focus();
	}
}

Regards,
Nasko