1

How can i add watermark to textbox in WINRT XAML C# code for Windows 8 application. There is a direct property for tooltip but same is not for Watermark so what is the shortest and efficient way to implement this?

3 Answers 3

6
  • Goto ManageNugetPacageManager -> search for Winrt Xaml Toolkit -> then install the winrt xaml toolkit

  • then goto xaml page where you want to add watermark textbox

  • Then define the below namespace to xaml page xmlns:local="using:WinRTXamlToolkit.Controls"

  • then goto the position where you want to add watermarktextbox add this following line below <local:WatermarkTextBox WatermarkText="MyWaterMarkText" />

i hope it works for you!

2

Fill a control with the watermark you want to display, such as an Image control, place a TextBox over it (such as by putting them both in a grid with the same Row and Column) and set the Background to Brushes.Transparent.

See Set background color of WPF Textbox in C# code for more information on Brushes and setting the TextBox pacground.

2

You could also use the WatermarkTextBox from the WinRT XAML Toolkit for out of the box solution. You could also implement one as an attached behavior using a Popup or by injecting a watermark TextBlock (or any other watermark UIElement) into the visual tree of the TextBox (though that is not supported by the Toolkit... yet).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.