我正在爲windows phone 7構建一個應用程序。我有一個帶有幾個文本框的窗體。現在我想在我的表單中放置佔位符,這是我以編程方式創建的。在某些情況下,當我點擊TextBox
佔位符被清除時,它工作正常。但它像一個價值。該文本框不被視爲包含空值。請看看我的代碼:在windows phone 7應用程序的文本框中佔位
的XAML:
<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"/>
銫文件:
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;
}
}
我想不被認爲是值的佔位符。請幫忙。
我該如何使用它。請使用Google搜索幫助 – bhaku
。首先閱讀文檔 –
我也添加了一個鏈接。如果您覺得我的回答是正確的,請將其標記爲答案。希望它有幫助。 –