简体   繁体   English

如何在wp7应用程序的文本框中提供占位符

[英]how to give a placeholder in a textbox in wp7 application

I am building an app for windows phone 7 where i have a textbox in which i want to place a placeholder. 我正在为Windows Phone 7构建一个应用程序,其中有一个我要在其中放置占位符的文本框。

My xaml is: 我的xaml是:

<TextBox Height="73" HorizontalAlignment="Left" Margin="18,45,0,0"  Name="name"  Text="Name" VerticalAlignment="Top" Width="419" />

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 wp7文本框中没有占位符或水印的特殊属性

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 并订阅其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. 希望这可以帮助。

您应该尝试使用具有提示属性的Windows Phone工具包( http://phone.codeplex.com/ )中的PhoneTextBox。

You mean you have to place a cursor when App get's launched. 您的意思是启动应用程序获取时必须放置一个光标。 If yes, then go for GotFocus event. 如果是,则参加GotFocus事件。

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;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM