相关疑难解决方法(0)

水印/提示文本/占位符TextBox

如何将一些文本放入文本框中,当用户在其中键入内容时会自动将其删除?(在WPF中)

c# wpf textbox watermark hint

246
推荐指数
12
解决办法
21万
查看次数

如何在WPF中为搜索框实现默认文本?

我想为WPF搜索TextBox 实现与" 更改搜索框中的默认文本 "完全相同的内容.当文本被输入时,该框应该显示一些灰色的"搜索..."文本,然后它应该在输入文本时正常运行.链接的文章显示了如何在javascript中执行此操作.如何在WPF中开始这条路?到目前为止,我所拥有的最好的想法是在主要文本框之上的另一个文本框,只要搜索文本框获得焦点或文本,该文本框就不可见.

wpf search textbox

7
推荐指数
2
解决办法
1万
查看次数

在WPF UserControl中附加ICommand

我实现了一个带有图像的简单按钮:

    <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)

c# wpf user-controls mvvm

7
推荐指数
1
解决办法
2万
查看次数

如何在代码中向文本框添加materialDesign:Hint

<TextBox md:HintAssist.Hint="Dinheiro" md:HintAssist.Background="#FFF"  />
Run Code Online (Sandbox Code Playgroud)

如何创建一个带有类似代码提示的文本框?

c# wpf material-design-in-xaml

2
推荐指数
1
解决办法
2067
查看次数