Place holder or watermark in TextBox windows 8(TextBox windows 8中的占位符或水印)
问题描述
当用户没有输入任何内容并且 TextBox
空闲时,我想在 TextBox
中显示占位符文本.
在 Andriod 中可以使用 android:hint="some Text"
在 iPhone 中,它可以作为 textFild.placeholder = "some text";
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 android:hint="some Text"
In iPhone it can be done as textFild.placeholder = "some text";
如何在 Windows 8 Metro 应用程序中执行此操作?
How can I do it in windows 8 metro apps?
谢谢
推荐答案
Edit for windows-8.1 他们引入了一个新属性
Edit for windows-8.1 they have introduced a new property
<TextBox x:Name="UserName" PlaceholderText="User Name"/>
请参阅 Sergey Aldoukhov 的回答
对我来说,这是我得到的有效解决方案.如果有人有更好的解决方案请回答.
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 也做同样的检查 这里的例子.
P.S.我为 TextBox
创建了一个自定义控件,您可以从 here 下载它/strong>
P.S. I have created a custom control for TextBox
you can download it from here
这篇关于TextBox windows 8中的占位符或水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TextBox windows 8中的占位符或水印


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01