简体   繁体   English

单击按钮时如何验证空文本框?

[英]how to validation empty textbox when button click wpf?

I'm new in wpf and i want to make validation with error message on any empty text box user left when he click button to store data to database. 我是wpf的新手,我想对单击按钮以将数据存储到数据库时留下的任何空文本框用户进行错误消息验证。 I tried this in View Model. 我在视图模型中尝试过。 But its showing same message (Please enter all the scan details) for all field. 但是它在所有字段中显示相同的消息(请输入所有扫描详细信息)。 is this ways is correct? 这是正确的方法吗? or any other way is there to get Changed particular Message (like: Please enter the Name!) for each textbox? 还是通过其他任何方式获取每个文本框的已更改的特定消息(例如:请输入名称!)? and how to focus that empty particular textbox? 以及如何聚焦那个空的特定文本框? Please help. 请帮忙。

if (String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(Mode) || String.IsNullOrEmpty(Url) || String.IsNullOrEmpty(Address))
            {
                MessageBox.Show("Please enter all the scan details first.", "Info", MessageBoxButton.OK);
                return;
            }
            else
            {
                SaveModelToDatabase();
                MessageBox.Show("Successfully saved!", "Info", MessageBoxButton.OK);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM