I have implemented a validation for Datagrid cell template using IDataErrorInfo and can able to show a tooltip error message. How can i display a messagebox with error information instead of tooltip?
<DataGridTemplateColumn Header="Code" MinWidth="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Code, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" Style="{StaticResource TextBlockStyle}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding Code, UpdateSourceTrigger=LostFocus}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
IDataErrorInfo implemented class
public class CurrencyExchangeRate : ObservableObject, IDataErrorInfo
{
private string _code;
public string Code
{
get { return _code; }
set
{
if (_code != value)
{
_code = value;
if (!string.IsNullOrEmpty(_code))
{
RaisePropertyChangedEvent("Code");
}
}
}
}
public string this[string columnName]
{
get
{
string error = string.Empty;
switch (columnName)
{
case "Code":
if (string.IsNullOrEmpty(_code))
{
error = "Code cannot be empty";
ShowMessage(error);
}
break;
}
return error;
}
}
public static void ShowMessage(string error)
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
System.Windows.Forms.MessageBox.Show(error);
}));
}
}