2017-10-15 54 views
0

我是XAML和WPF的新手。PlaceholderText无法访问XAML

我想添加一个占位符到我的文本框,但我得到这个错误:“属性'PlaceholderText'找不到类型'文本框'”和“成员”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> 

回答

4

你有代码的文档是从一个文档Windows.UI.Xaml.Controls.TextBox,这是通用Windows应用程序中使用的文本框控件。这有一个属性叫PlaceholderText

WPF之一是System.Windows.Controls.TextBox,这是不同的,并没有PlaceholderText属性。为了拥有像WPF中的UWP占位符文本这样的东西,您必须自己实现它或使用第三方库来提供对此功能的控制。