Files
XplorePlane/XP.Camera/Calibration/Controls/CalibrationControl.xaml.cs
T

64 lines
1.7 KiB
C#

using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using XP.Camera.Calibration.ViewModels;
using XP.ImageProcessing.RoiControl.Controls;
namespace XP.Camera.Calibration.Controls;
public partial class CalibrationControl : UserControl
{
private CalibrationViewModel? _viewModel;
public CalibrationControl()
{
InitializeComponent();
Loaded += CalibrationControl_Loaded;
}
private void CalibrationControl_Loaded(object sender, RoutedEventArgs e)
{
if (DataContext is CalibrationViewModel viewModel)
{
_viewModel = viewModel;
_viewModel.PropertyChanged += OnViewModelPropertyChanged;
}
}
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(CalibrationViewModel.OverlayImage))
{
UpdateDetectionOverlay();
}
}
private void UpdateDetectionOverlay()
{
if (_viewModel?.OverlayImage == null)
{
roiCanvas.ClearDetectionOverlay();
return;
}
var overlayCanvas = new Canvas
{
Width = _viewModel.OverlayImage.PixelWidth,
Height = _viewModel.OverlayImage.PixelHeight,
IsHitTestVisible = false
};
var image = new System.Windows.Controls.Image
{
Source = _viewModel.OverlayImage,
Width = _viewModel.OverlayImage.PixelWidth,
Height = _viewModel.OverlayImage.PixelHeight,
IsHitTestVisible = false
};
overlayCanvas.Children.Add(image);
roiCanvas.SetDetectionOverlayCanvas(overlayCanvas);
}
}