我是XAML和WPF的新手。
我正在尝试在我的文本框中添加占位符,但是我收到了此错误:"属性' PlaceholderText'没有找到类型' TextBox'"和"会员" PlaceholderText"未被识别或无法访问"。
当我尝试输入PlaceholderText时,它甚至没有显示在自动完成下拉列表中。 "头"有问题。
我正在使用VS 2015社区和.NET Framework 4.5.2
以下是我从https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textbox#Examples
获取的代码<Window x:Class="QuickGarbageSort.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyTestApp"
mc:Ignorable="d"
Title="MyTestApp" Height="550" Width="800">
<StackPanel>
<TextBlock Text="What's your name?"/>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBox x:Name="nameInput"
Header="Enter your name:" PlaceholderText="Name"
Width="300" HorizontalAlignment="Left"/>
<Button Content="Hello button" Click="Button_Click"/>
</StackPanel>
<TextBlock x:Name="greetingOutput"/>
</StackPanel>
答案 0 :(得分:4)
您从中获取代码的文档是Windows.UI.Xaml.Controls.TextBox
的文档,这是Universal Windows Applications中使用的文本框控件。这有一个名为PlaceholderText
WPF一个是System.Windows.Controls.TextBox
,这是不同的,没有PlaceholderText
属性。为了在WPF中使用类似UWP的占位符文本,您必须自己实现它或使用第三方库来提供具有此功能的控件。