如何约束文本框 [英] How to constrain a TextBox

查看:69
本文介绍了如何约束文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 TextBox 以仅获取某些值。例如 DateTime 输入框,其中包含定义的格式设置。

How to set up a TextBox to get only certain values. e.g. DateTime input box with defined format settings.

推荐答案

http://www.codeproject.com/KB/WPF/wpfvalidation.aspx

<TextBox Text="{Binding Path=Name}" />

还有一个函数。这只是检查字符串是否包含内容。根据您要强制执行的确切格式,您会更复杂:

And a function. This one just checks the string has content. Yours will be more complex depending on the exact format you want to enforce:

public string Name
{
    get { return _name; }
    set
    {
        _name = value;
        if (String.IsNullOrEmpty(value))
        {
            throw new ApplicationException("Customer name is mandatory.");
        }
    }
}

这篇关于如何约束文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆