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中的占位符或水印
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
