i want to have a placeholder in my textbox in wpf.. i tried to search xaml script to solve my problem, and i find that xaml codes are too long for simple placeholder, then i end up with my own solution.. is event handlers will slow down an app?
Dim myPlaceholder As String = "My Sample Placeholder"
Private Sub tbStarSign_GotFocus(sender As Object, e As RoutedEventArgs) Handles tbStarSign.GotFocus
If tbStarSign.Text = myPlaceholder Then
tbStarSign.Text = ""
End If
End Sub
Private Sub tbStarSign_LostFocus(sender As Object, e As RoutedEventArgs) Handles tbStarSign.LostFocus
If tbStarSign.Text = "" Then
tbStarSign.Text = myPlaceholder
End If
End Sub
.
There's nothing wrong with a XAML only solution.
Usage: