Ind*_*ore 16 c# microsoft-metro windows-8 .net-4.5
我希望在TextBox用户没有键入任何内容并且TextBox处于空闲状态时显示占位符文本.
在Andriod中,可以使用 android:hint="some Text"
In iPhone完成它textFild.placeholder = "some text";
我如何在Windows 8 metro应用程序中执行此操作?
谢谢
Ind*_*ore 24
编辑windows-8.1他们引入了一个新属性
<TextBox x:Name="UserName" PlaceholderText="User Name"/>
Run Code Online (Sandbox Code Playgroud)
对我来说,这是我得到的工作解决方案.
如果任何人有更好的解决方案,请回答.
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...";
}
}
Run Code Online (Sandbox Code Playgroud)
PS我已经创建了一个自定义控件,TextBox你可以从这里下载它
在Windows 8.1中,TextBox具有PlaceholderText属性:
<TextBox
x:Name="UserName"
PlaceholderText="User Name"
/>
Run Code Online (Sandbox Code Playgroud)
WinRT Xaml工具包有一个WatermarkTextbox控件:http: //winrtxamltoolkit.codeplex.com/
您也可以通过NuGet获取它,它还有其他几个有用的控件.
你可以通过在你的Page's属性中引用工具包来使用它:
xmlns:xtk="using:WinRTXamlToolkit.Controls"
Run Code Online (Sandbox Code Playgroud)
只需访问WaterMarkTextBox,如下所示:
<xtk:WatermarkTextBox WatermarkText="some text" />
Run Code Online (Sandbox Code Playgroud)
编辑.:
Callisto也提供了水印TextBox:https: //github.com/timheuer/callisto
它只是在自述文件中没有提到.
| 归档时间: |
|
| 查看次数: |
11769 次 |
| 最近记录: |