Code: Select all
/// <summary>
/// User started the annotation building.
/// </summary>
private void buildAnnotationButton_Click(object sender, RoutedEventArgs e)
{
try
{
// create annotation view
WpfAnnotationView annotationView = new WpfRectangleAnnotationView(new RectangleAnnotationData());
if (annotationView != null)
{
// subscribe from the Interaction event of annotation builder
annotationView.Builder.Interaction += Builder_Interaction;
// start annotation building
Viewer.AnnotationVisualTool.AddAndBuildAnnotation(annotationView);
}
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message, "Building annotation", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// Handles the Interaction event of the annotation builder.
/// </summary>
void Builder_Interaction(
object sender,
Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionEventArgs e)
{
// desired annotation width and height
double annoWidth = 100;
double annoHeight = 100;
// change the start and end location of interaction - this is necessary for correct Location and Size of annotation
e.StartLocation = e.Location;
e.Location = new System.Windows.Point(e.Location.X + annoWidth, e.Location.Y + annoHeight);
// specify that interaction is finished
e.InteractionFinished = true;
WpfAnnotationViewer annotationViewer = (WpfAnnotationViewer)e.Viewer;
WpfAnnotationView annotationView = annotationViewer.FocusedAnnotationView;
// unsubscribe from the Interaction event of annotation builder
annotationView.Builder.Interaction -= Builder_Interaction;
// set annotation parameters (Location and Size will be set by builder)
annotationView.CanResize = false;
}