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?

Balraj Singh
  • 3,381
  • 6
  • 47
  • 82

3 Answers3

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!

pashaplus
  • 3,596
  • 2
  • 26
  • 25
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.

Community
  • 1
  • 1
akton
  • 14,148
  • 3
  • 43
  • 47
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).

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100