Windows Phone 7 应用程序中文本框中的占位符 [英] Placeholder in textbox in windows phone 7 application

查看:25
本文介绍了Windows Phone 7 应用程序中文本框中的占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows Phone 7 构建一个应用程序.我有一个包含几个文本框的表单.现在我想在我以编程方式创建的表单中放置一个占位符.在某些情况下,它工作正常,就像当我单击 TextBox 时,占位符被清除.但它就像一个值.文本框不被视为包含 Null 值.请看一下我的代码:

I am building an app for windows phone 7. I have a form with a few TextBoxes. Now I want to put a placeholder in my form which I have created programmatically. In some cases it works fine like when I click the TextBox the placeholder is cleared. But it works like a value. The text box is not considered to contain Null value. Please have a look at my code:

XML:

<TextBox GotFocus="OnGotFocus" Canvas.Left="6" Canvas.Top="6" Height="74" Name="name" Text="*Name" Width="453" BorderThickness="0"/>
            <TextBox GotFocus="OnGotFocus1" Canvas.Left="6" Canvas.Top="66" Height="74" Name="age" Text="*Age" Width="453" BorderThickness="0" />
            <TextBlock Canvas.Left="20" Canvas.Top="157" Height="44" Name="gen" Text="Gender" Foreground="Black" FontFamily="Verdana" FontSize="24" Width="134" />
            <RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
            <RadioButton Canvas.Left="139" Canvas.Top="207"  FontStyle="Italic" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
            <TextBox GotFocus="OnGotFocus2" Canvas.Left="6" Canvas.Top="267" Height="74" Name="sadd" Text="*Street Address" Width="453" BorderThickness="0"/>
            <TextBox GotFocus="OnGotFocus3" Canvas.Left="6" Canvas.Top="327" Height="74" Name="cadd" Text="*City Address" Width="453" BorderThickness="0"/>
            <TextBox GotFocus="OnGotFocus4" Canvas.Left="6" Canvas.Top="387" Height="74" Name="eadd" Text="*Email Address" Width="453" BorderThickness="0"/>
            <TextBox GotFocus="OnGotFocus5" Canvas.Left="6" Canvas.Top="447" Height="74" Name="phn" Text="*Phone" Width="453" BorderThickness="0"/>
            <TextBox GotFocus="OnGotFocus6" Canvas.Left="6" Canvas.Top="507" Height="74" Name="zip" Text="*Zip Code" Width="453" BorderThickness="0"/>

Cs 文件:

private void OnGotFocus(object sender, RoutedEventArgs e)
    {
        if (name.Text.Equals("*Name", StringComparison.OrdinalIgnoreCase))
        {
            name.Text = string.Empty;
        }
    }

    private void OnGotFocus1(object sender, RoutedEventArgs e)
    {
        if (age.Text.Equals("*Age", StringComparison.OrdinalIgnoreCase))
        {
            age.Text = string.Empty;
        }
    }

    private void OnGotFocus2(object sender, RoutedEventArgs e)
    {
        if (sadd.Text.Equals("*Street Address", StringComparison.OrdinalIgnoreCase))
        {
            sadd.Text = string.Empty;
        }
    }

    private void OnGotFocus3(object sender, RoutedEventArgs e)
    {
        if (cadd.Text.Equals("*City Address", StringComparison.OrdinalIgnoreCase))
        {
            cadd.Text = string.Empty;
        }
    }

    private void OnGotFocus4(object sender, RoutedEventArgs e)
    {
        if (eadd.Text.Equals("*Email Address", StringComparison.OrdinalIgnoreCase))
        {
            eadd.Text = string.Empty;
        }
    }

    private void OnGotFocus5(object sender, RoutedEventArgs e)
    {
        if (phn.Text.Equals("Phone", StringComparison.OrdinalIgnoreCase))
        {
            phn.Text = string.Empty;
        }
    }

    private void OnGotFocus6(object sender, RoutedEventArgs e)
    {
        if (zip.Text.Equals("*Zip Code", StringComparison.OrdinalIgnoreCase))
        {
            zip.Text = string.Empty;
        }
    }

我希望占位符不被视为一个值.请帮忙.

I want the placeholder not to be considered as a value. Please help.

推荐答案

你看过 windows toolkit 的 PhonetextBox,它有一个提示属性.应该能帮到你.

have you looked at windows toolkit's PhonetextBox, it has a hint property. It should help you.

这篇关于Windows Phone 7 应用程序中文本框中的占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆