Centering the watermark

7 posts, 1 answers
  1. Doug
    Doug avatar
    49 posts
    Member since:
    May 2012

    Posted 13 Jul 2012 Link to this post

    Hi telerik.

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

    Best Regards
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 16 Jul 2012 Link to this post

    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.

  3. DevCraft banner
  4. Doug
    Doug avatar
    49 posts
    Member since:
    May 2012

    Posted 16 Jul 2012 Link to this post

    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.
  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 16 Jul 2012 Link to this post

    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.

  6. Doug
    Doug avatar
    49 posts
    Member since:
    May 2012

    Posted 16 Jul 2012 Link to this post

    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
  7. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 16 Jul 2012 Link to this post

    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.

  8. Doug
    Doug avatar
    49 posts
    Member since:
    May 2012

    Posted 17 Jul 2012 Link to this post

    Thank you for your help, that helped me!

    Best Regards Doug
Back to Top
DevCraft banner