Windows phone 7 标题位于文本框内的WP7文本框

Windows phone 7 标题位于文本框内的WP7文本框,windows-phone-7,Windows Phone 7,我想有一个文本框,让用户输入一些文本(显然)。让我们说它是“标题”。是否有一个预构建控件,在文本框中显示字段名称(本例中为标题),然后在用户输入字段时将其清除。示例:此页面顶部的搜索框具有“搜索”功能,但当您输入该框时,它将消失。 我想我记得它也在Mango Silverlight工具包中,如果我错了,请纠正我: 这是一个例子。将GotFocus和LostFocus事件放在文本框中(在.xaml页面中) 在xaml.cs页面中,添加以下代码- private void UrlText

我想有一个文本框,让用户输入一些文本(显然)。让我们说它是“标题”。是否有一个预构建控件,在文本框中显示字段名称(本例中为标题),然后在用户输入字段时将其清除。示例:此页面顶部的搜索框具有“搜索”功能,但当您输入该框时,它将消失。

我想我记得它也在Mango Silverlight工具包中,如果我错了,请纠正我:
这是一个例子。将GotFocus和LostFocus事件放在文本框中(在.xaml页面中)


在xaml.cs页面中,添加以下代码-

    private void UrlTextBox_GotFocus(object sender, RoutedEventArgs e)
    {
        if (UrlTextBox.Text == "Search")
        {
            UrlTextBox.Text = "";
            SolidColorBrush Brush1 = new SolidColorBrush();
            Brush1.Color = Colors.Gray;
            UrlTextBox.Foreground = Brush1;
        }

        else
        {
            char[] strDataAsChars = UrlTextBox.Text.ToCharArray();
            int i = 0;
            for (i = UrlTextBox.SelectionStart - 1; ((i >= 0) &&
                               (strDataAsChars[i] != ' ')); --i) ;
            int selBegin = i + 1;
            for (i = UrlTextBox.SelectionStart; ((i < strDataAsChars.Length) &&
                                              (strDataAsChars[i] != ' ')); ++i) ;
            int selEnd = i;
            UrlTextBox.Select(selBegin, selEnd - selBegin);
        }
    }

    private void UrlTextBox_LostFocus(object sender, RoutedEventArgs e)
    {
        if (UrlTextBox.Text == String.Empty)
        {
            UrlTextBox.Text = "Search";
            SolidColorBrush Brush2 = new SolidColorBrush();
            Brush2.Color = Colors.Gray;
            UrlTextBox.Foreground = Brush2;
        }
    }
private void URLTEXBOX\u GotFocus(对象发送方,RoutedEventArgs e)
{
如果(UrlTextBox.Text==“搜索”)
{
UrlTextBox.Text=“”;
SolidColorBrush1=新的SolidColorBrush();
笔刷1.颜色=颜色。灰色;
UrlTextBox.Foreground=Brush1;
}
其他的
{
char[]strDataAsChars=UrlTextBox.Text.ToCharray();
int i=0;
对于(i=UrlTextBox.SelectionStart-1;((i>=0)&&
(strDataAsChars[i]!=”);--i);
int selbeng=i+1;
对于(i=UrlTextBox.SelectionStart;((i
谢谢,但我希望避免自己建造它。我将把模拟器更新为mango并尝试使用PhoneTextBox。谢谢
    private void UrlTextBox_GotFocus(object sender, RoutedEventArgs e)
    {
        if (UrlTextBox.Text == "Search")
        {
            UrlTextBox.Text = "";
            SolidColorBrush Brush1 = new SolidColorBrush();
            Brush1.Color = Colors.Gray;
            UrlTextBox.Foreground = Brush1;
        }

        else
        {
            char[] strDataAsChars = UrlTextBox.Text.ToCharArray();
            int i = 0;
            for (i = UrlTextBox.SelectionStart - 1; ((i >= 0) &&
                               (strDataAsChars[i] != ' ')); --i) ;
            int selBegin = i + 1;
            for (i = UrlTextBox.SelectionStart; ((i < strDataAsChars.Length) &&
                                              (strDataAsChars[i] != ' ')); ++i) ;
            int selEnd = i;
            UrlTextBox.Select(selBegin, selEnd - selBegin);
        }
    }

    private void UrlTextBox_LostFocus(object sender, RoutedEventArgs e)
    {
        if (UrlTextBox.Text == String.Empty)
        {
            UrlTextBox.Text = "Search";
            SolidColorBrush Brush2 = new SolidColorBrush();
            Brush2.Color = Colors.Gray;
            UrlTextBox.Foreground = Brush2;
        }
    }