Place holder or watermark in TextBox windows 8

后端 未结 5 1011
既然无缘
既然无缘 2021-01-08 00:38

I want to show a placeholder text in TextBox when user hasn\'t typed anything and TextBox is idle.

In Andriod it can be done using a

5条回答
  •  广开言路
    2021-01-08 01:17

    Edit for windows-8.1 they have introduced a new property

    
    

    Please see Sergey Aldoukhov's answer


    For me this is the working solution that I got.
    If any one has better solution please answer.

    private void OnTestTextBoxGotFocus(object sender, RoutedEventArgs e)
    {
        if (testTextBox.Text.Equals("Type here...", StringComparison.OrdinalIgnoreCase))
        {
            testTextBox.Text = string.Empty;
        }  
    }
    
    private void OnTestTextBoxLostFocus(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(testTextBox.Text))
        {
            testTextBox.Text = "Type here...";
        }
    }
    


    MS also do the same check the example here.

    P.S. I have created a custom control for TextBox you can download it from here

提交回复
热议问题