Skip to main content

How to add error messages that appear during processing

image.png

When Zonal OCR is processing files it will display this big red box if an error occurs. If you ever need to add a new type of message that should appear, follow these instructions.

Required Files to Update

FileState.cs
Add an enum value for your new error.

FileStateToHintConverter.cs
Add the text that will be displayed when the error occurs.

FormsOcr.ResourceDictionary.xaml
Find the <Style TargetType="{x:Type userControls:ErrorMessage}"> tag. Add a child <DataTrigger> tag for your new FileState enum

FileStatisticsModel.cs
Add your new enum to the FailedCount getter.

Windows Notification

image.png

If you want your error to also appear as a Windows notification (which is probably what you want), you also need to make this change.

TrayNotificationHelper.cs
Add your new enum to the errorsState list.

Triggering the Error

All that's left is to trigger the error at the appropriate time. Simply set the FileState property on the FileView model to the value of your new enum.

The red error box will automatically appear because its text value is bound to the FileView. The Windows notification will automatically appear because the FileState setter notifies the TrayNotificationHelper of its new value.

References

See commit {something} in the ZonalOCR git repository for an example.