/// <summary> /// A new ImageViewer has been created. /// For simplicity this sample adds the same UIElements to all ImageViewers. In real life it should in most cases be dependent on the camera. Look at the AnalyticsOverlay sample for an example on how to do this. /// </summary> /// <param name="imageViewerAddOn"></param> void NewImageViewerControlEvent(ImageViewerAddOn imageViewerAddOn) { imageViewerAddOn.ShowMetadataOverlay = false; Guid borderId = AddBorder(imageViewerAddOn); var button = new Button() { Content = "Toggle bounding box", Width = 150, Height = 30, Background = Brushes.Transparent, Tag = borderId, // storing the ID for the border active element so that we can use it for toggling HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 10, 10, 0) }; button.Click += Button_Click; var textBlock = new TextBlock() { Text = "This is an element" + System.Environment.NewLine + "that doesn't capture any mouse events", IsHitTestVisible = false // this will ensure that the text will not capture any mouse events }; // position is set relative to the top of the video being shown - not the entire view item Canvas.SetLeft(textBlock, 250); Canvas.SetTop(textBlock, 250); imageViewerAddOn.ActiveElementsOverlayAdd(new List <FrameworkElement> { button, textBlock }, new ActiveElementsOverlayRenderParameters() { FollowDigitalZoom = false, ShowAlways = false, ZOrder = 1 }); RegisterEvents(imageViewerAddOn); lock (_imageViewerAddOnButtons) { _imageViewerAddOnButtons[imageViewerAddOn] = button; } }
private Guid AddBorder(ImageViewerAddOn imageViewerAddOn) { var border = new Border() { BorderBrush = Brushes.Green, BorderThickness = new Thickness(2), Width = 100, Height = 100 }; border.MouseDown += Border_MouseDown; border.MouseEnter += Border_MouseEnter; border.MouseLeave += Border_MouseLeave; Canvas.SetLeft(border, 42); Canvas.SetTop(border, 42); return(imageViewerAddOn.ActiveElementsOverlayAdd(new List <FrameworkElement> { border }, new ActiveElementsOverlayRenderParameters() { FollowDigitalZoom = true, ShowAlways = true, ZOrder = 2 })); }