2014-02-14 103 views
0

我正在爲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; 
     } 
    } 

我想不被認爲是值的佔位符。請幫忙。

回答

1

你看過windows工具包的PhonetextBox,它有一個提示屬性。它應該幫助你。

+0

我該如何使用它。請使用Google搜索幫助 – bhaku

+0

。首先閱讀文檔 –

+0

我也添加了一個鏈接。如果您覺得我的回答是正確的,請將其標記爲答案。希望它有幫助。 –

1

你也可以使用codeplex提供的水印文本框控件。它會根據您的需求工作

here是鏈接。