Reputation: 3471
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?
Upvotes: 1
Views: 4307
Reputation: 31724
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).
Upvotes: 2
Reputation: 3706
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!
Upvotes: 6
Reputation: 14386
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.
Upvotes: 2