实时过程中禁用图像预览窗体的滚轮缩放功能

This commit is contained in:
zhengxuan.zhang
2026-06-01 15:07:28 +08:00
parent 5a11af9ab1
commit ad1fdb0230
3 changed files with 31 additions and 0 deletions
@@ -176,6 +176,20 @@ namespace XP.ImageProcessing.RoiControl.Controls
control.UpdateAdorner(); control.UpdateAdorner();
} }
/// <summary>
/// 是否允许滚轮缩放(默认允许)。
/// 实时图像显示过程中可设为 false 以禁用滚轮缩放。
/// </summary>
public static readonly DependencyProperty IsWheelZoomEnabledProperty =
DependencyProperty.Register(nameof(IsWheelZoomEnabled), typeof(bool), typeof(PolygonRoiCanvas),
new PropertyMetadata(true));
public bool IsWheelZoomEnabled
{
get => (bool)GetValue(IsWheelZoomEnabledProperty);
set => SetValue(IsWheelZoomEnabledProperty, value);
}
public static readonly DependencyProperty PanOffsetXProperty = public static readonly DependencyProperty PanOffsetXProperty =
DependencyProperty.Register(nameof(PanOffsetX), typeof(double), typeof(PolygonRoiCanvas), DependencyProperty.Register(nameof(PanOffsetX), typeof(double), typeof(PolygonRoiCanvas),
new PropertyMetadata(0.0, OnPanOffsetChanged)); new PropertyMetadata(0.0, OnPanOffsetChanged));
@@ -2209,6 +2223,13 @@ namespace XP.ImageProcessing.RoiControl.Controls
private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e) private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
{ {
// 实时显示过程中禁用滚轮缩放
if (!IsWheelZoomEnabled)
{
e.Handled = true;
return;
}
double oldZoom = ZoomScale; double oldZoom = ZoomScale;
double newZoom = e.Delta > 0 ? oldZoom * ZoomStep : oldZoom / ZoomStep; double newZoom = e.Delta > 0 ? oldZoom * ZoomStep : oldZoom / ZoomStep;
newZoom = Math.Max(0.1, Math.Min(10.0, newZoom)); newZoom = Math.Max(0.1, Math.Min(10.0, newZoom));
@@ -94,10 +94,18 @@ namespace XplorePlane.ViewModels
set set
{ {
if (SetProperty(ref _isRealtimeEnabled, value)) if (SetProperty(ref _isRealtimeEnabled, value))
{
_mainViewportService.SetRealtimeDisplayEnabled(value); _mainViewportService.SetRealtimeDisplayEnabled(value);
RaisePropertyChanged(nameof(IsWheelZoomEnabled));
}
} }
} }
/// <summary>
/// 是否允许滚轮缩放:实时显示过程中禁用,停止实时后可缩放。
/// </summary>
public bool IsWheelZoomEnabled => !_isRealtimeEnabled;
// Task 5.3: IsDetectorConnected property (read-only, private setter) // Task 5.3: IsDetectorConnected property (read-only, private setter)
public bool IsDetectorConnected public bool IsDetectorConnected
{ {
@@ -227,6 +235,7 @@ namespace XplorePlane.ViewModels
// Task 5.8: Sync IsRealtimeEnabled from service // Task 5.8: Sync IsRealtimeEnabled from service
_isRealtimeEnabled = _mainViewportService.IsRealtimeDisplayEnabled; _isRealtimeEnabled = _mainViewportService.IsRealtimeDisplayEnabled;
RaisePropertyChanged(nameof(IsRealtimeEnabled)); RaisePropertyChanged(nameof(IsRealtimeEnabled));
RaisePropertyChanged(nameof(IsWheelZoomEnabled));
// Task 5.8: Sync _isCncRunning from service and raise IsAnimatedSwitchEnabled // Task 5.8: Sync _isCncRunning from service and raise IsAnimatedSwitchEnabled
_isCncRunning = _mainViewportService.IsCncRunning; _isCncRunning = _mainViewportService.IsCncRunning;
@@ -35,6 +35,7 @@
x:Name="RoiCanvas" x:Name="RoiCanvas"
Background="White" Background="White"
ImageSource="{Binding ImageSource}" ImageSource="{Binding ImageSource}"
IsWheelZoomEnabled="{Binding IsWheelZoomEnabled}"
ScaleBarMmPerPixel="0.139" ScaleBarMmPerPixel="0.139"
ShowScaleBar="{Binding DataContext.IsScaleBarVisible, RelativeSource={RelativeSource AncestorType=Window}}" /> ShowScaleBar="{Binding DataContext.IsScaleBarVisible, RelativeSource={RelativeSource AncestorType=Window}}" />
</Grid> </Grid>