Sorry for my English,
I have a windows application using MVVM architecture. I have a View with differents controls. One of them is a textbox. I need to validate de user-entered value and set a specific value in the attribute and in a view if the user-entered value is incorrect. I must use the binding property of the textbox. It is not allowed me to use event control...for example PreviewTextInput.
For example, this is my control:
<TextBox Height="23" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
I need In the case that the user enters digit the textbox does not allow this. I need In the case that the user enters negative number set value 1 in the attribute Name and show in the textbox this value. Also, I need if the user enters a value greater of 50 set in the attribute Name 50 and show in the view.
How I can do this?
thanks!
////////////////////////
thank you very much, Raul the problem is that I cant displaying error messages (company policy...) I need to replace the erroneous value with a valid value. For example:
public string Name
{
{get { return _name; }
set
{
_name = value;
if (String.IsNullOrEmpty(value))
{
// throw new ApplicationException("Customer name is mandatory.");
}
}
}
// Instead of throwing an exception, set in the textbox the numeric value //50...like
if (string.IsNullOrEmpty(tbCasesNumber.Text))
{
txtName.text= "50";
}
How I can do this in WPF?