如何将一些文本放入文本框中,当用户在其中键入内容时会自动将其删除?(在WPF中)
我想为WPF搜索TextBox 实现与" 更改搜索框中的默认文本 "完全相同的内容.当文本被输入时,该框应该显示一些灰色的"搜索..."文本,然后它应该在输入文本时正常运行.链接的文章显示了如何在javascript中执行此操作.如何在WPF中开始这条路?到目前为止,我所拥有的最好的想法是在主要文本框之上的另一个文本框,只要搜索文本框获得焦点或文本,该文本框就不可见.
我实现了一个带有图像的简单按钮:
<Button Command="{Binding ButtonCommand, ElementName=ImageButtonControl}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ButtonImage, ElementName=ImageButtonControl}"/>
<TextBlock Text="{Binding ButtonText, ElementName=ImageButtonControl}" Margin="2,0,0,0"/>
</StackPanel>
</Button>
Run Code Online (Sandbox Code Playgroud)
如您所见,我公开了一个ButtonCommand属性,以便能够将ICommand附加到此UserControl:
public partial class ImageButton : UserControl
{
/// <summary>
/// The dependency property that gets or sets the source of the image to render.
/// </summary>
public static DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ButtonImage", typeof(ImageSource), typeof(ImageButton));
public static DependencyProperty TextProperty =
DependencyProperty.Register("ButtonText", typeof(string), typeof(ImageButton));
public static DependencyProperty ButtonCommandProperty =
DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(ImageButton));
public ImageButton()
{
this.DataContext = this;
InitializeComponent();
}
/// <summary>
/// …Run Code Online (Sandbox Code Playgroud) <TextBox md:HintAssist.Hint="Dinheiro" md:HintAssist.Background="#FFF" />
Run Code Online (Sandbox Code Playgroud)
如何创建一个带有类似代码提示的文本框?