I have tabcontrol in wpf page and in the second tab I have usercontrol. But I using the save viewmodel to both. For validation I used IDataErrorInfo in viewmodel on button click. Validation works for in 1st tab. But in user control, validation works and red border shows around the control but didn't show the error message.
How do I show erro message in contentpresenter
Thanks in advance
My coding is (using mvvm light)
In View (usercontrol)
<textbox x:name="txtLength" grid.row="13" grid.column="2" borderthickness="2" borderbrush="#B6B6B4" text="{Binding Path=ProductShapeDetails.Length,Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,UpdateSourceTrigger=PropertyChanged}" margin="0,3,0,2" xmlns:x="#unknown" />
<contentpresenter name="cpLength" grid.row="14" grid.column="2" content="{Binding ElementName=ProductShapeDetails.Length, Path= (Validation.Errors).CurrentItem}" horizontalalignment="Left">
<contentpresenter.contenttemplate>
<datatemplate>
<textblock foreground="Red" text="{Binding Path= ErrorContent}" />
</datatemplate>
</contentpresenter.contenttemplate>
</contentpresenter>
In view model
public class RegisterProductViewModel : DataViewModelBase, INotifyPropertyChanged,IDataErrorInfo
{
public static Dictionary<string,>validationErrors = new Dictionary<string,>();
void ValidateShapes()
{
validationErrors.Clear();
if (SelectedGlaze == EnumGlazeType.None)
validationErrors.Add("SelectedGlaze","Please select Glaze type");
if (ProductShapeDetails.Length == 0)
validationErrors.Add("ProductShapeDetails.Length", "Length is required");
RaisePropertyChanged(null);
}
#region IDataErrorInfo Members
public string Error
{
get
{
if (validationErrors.Count > 0)
{
return "Errors found.";
}
return null;
}
}
public string this[string columnName]
{
get
{
if (validationErrors.ContainsKey(columnName))
{
return validationErrors[columnName];
}
return null;
}
}
#endregion
}