This is a migrated thread and some comments may be shown as answers.

Centering the watermark

6 Answers 90 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Doug
Top achievements
Rank 1
Doug asked on 13 Jul 2012, 09:42 AM
Hi telerik.

Can you provide some information on how to center the watermark for the RadTextBox?

Best Regards

6 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 16 Jul 2012, 05:44 AM
Hi Doug,

You can use the TextAlignment property to set both text and watermark's alignment to Left, Right, Center or Justify.

Regards,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Doug
Top achievements
Rank 1
answered on 16 Jul 2012, 09:13 AM
Hi Todor

The TextAlignment  property only changes the alignment of the input text but not the watermark. Also I want the text to be aligned to left and the watermark aligned to the center.
0
Todor
Telerik team
answered on 16 Jul 2012, 09:49 AM
Hello Doug,

Please accept my apologies for the misleading information in my previous post.
With our next internal build, we will make the alignment of the watermark dependent on the TextAlignment property.
However, if you want to have the watermark and the text with different TextAlignment, you will have to edit the control template of RadTextBox and set the desired alignment to the PART_Watermark.

Let me know if you need additional assistance.

Kind regards,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Doug
Top achievements
Rank 1
answered on 16 Jul 2012, 12:44 PM
Hi

"However, if you want to have the watermark and the text with different TextAlignment, you will have to edit the control template of RadTextBox and set the desired alignment to the PART_Watermark."

That is exactly what I would like to do, but I don't know how to apply a style to it.

it wont accept this:

    <Style x:Key="waterMarkStyle" TargetType="ContentControl">
        <Setter Property="FontStyle" Value="Italic"/>
        <Setter Property="FontSize" Value="25"/>
        <Setter Property="Foreground" Value="Black"/>
    </Style>

I would like help with that.

Thanks in advance
Best Regards
0
Accepted
Todor
Telerik team
answered on 16 Jul 2012, 01:56 PM
Hi Doug,

The watermark is not a ContentControl, it is a TextBlock. What I mean is to edit the ControlTemplate of RadTextBox. The easiest way to get the original template is by right-clicking the control in Blend and then selecting Edit Template -> Edit a Copy. Another way to achieve the alignment is to use the ElementTreeHelper class and get the desired element:

TextBlock watermark = ElementTreeHelper.FindVisualDescendant<TextBlock>(this.textBox,
    (t) =>
    {
        if (t as TextBlock != null && (t as TextBlock).Name == "PART_Watermark")
        {
            return true;
        }
        return false;
    });
watermark.TextAlignment = TextAlignment.Center;

I hope this information helps.

Greetings,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Doug
Top achievements
Rank 1
answered on 17 Jul 2012, 07:16 AM
Thank you for your help, that helped me!

Best Regards Doug
Tags
TextBox
Asked by
Doug
Top achievements
Rank 1
Answers by
Todor
Telerik team
Doug
Top achievements
Rank 1
Share this question
or