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中的占位符或水印


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01