Reputation: 448
I am building an app for windows phone 7 where i have a textbox in which i want to place a placeholder.
My xaml is:
<TextBox Height="73" HorizontalAlignment="Left" Margin="18,45,0,0" Name="name" Text="Name" VerticalAlignment="Top" Width="419" />
Upvotes: 0
Views: 143
Reputation: 6590
You mean you have to place a cursor when App get's launched. If yes, then go for GotFocus
event.
Try this :
<TextBox GotFocus="txt_OnGotFocus" Height="73" HorizontalAlignment="Left" Margin="18,45,0,0" Name="name" Text="Name" VerticalAlignment="Top" Width="419" />
Code behind
private void txt_OnGotFocus(object sender, RoutedEventArgs e)
{
if(this.name.Text == "Name")
{
this.name.Text = string.Empty;
}
}
Upvotes: 1
Reputation: 171
You should try the PhoneTextBox from the Windows Phone Toolkit (http://phone.codeplex.com/) which has a Hint property
Upvotes: 1
Reputation: 3331
If i am getting your question right and also if my knowledge serves me correctly then
There is no special property for placeholders or water mark in wp7 textboxes
How ever you can customize a textbox to fit in accordance to your needs.
Its just very simple
Taking your textbox which is
<TextBox Height="73" HorizontalAlignment="Left" Margin="18,45,0,0" Name="name" Text="Name" VerticalAlignment="Top" Width="419" />
and subscribing to its GotFocusEvent
<TextBox GotFocus="OnGotFocus" Height="73" HorizontalAlignment="Left" Margin="18,45,0,0" Name="name" Text="Name" VerticalAlignment="Top" Width="419" />
do this in the event handler
private void OnGotFocus(object sender, RoutedEventArgs e)
{
if (name.Text.Equals("Name", StringComparison.OrdinalIgnoreCase))
{
name.Text = string.Empty;
}
}
This could imitate your requirement.
Hope this helps.
Upvotes: 1