179 lines
11 KiB
XML
179 lines
11 KiB
XML
<UserControl x:Class="XP.ImageProcessing.RoiControl.Controls.PolygonRoiCanvas"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:local="clr-namespace:XP.ImageProcessing.RoiControl.Controls"
|
|
xmlns:models="clr-namespace:XP.ImageProcessing.RoiControl.Models"
|
|
xmlns:converters="clr-namespace:XP.ImageProcessing.RoiControl.Converters"
|
|
xmlns:behaviors="clr-namespace:XP.ImageProcessing.RoiControl"
|
|
mc:Ignorable="d"
|
|
d:DesignHeight="450" d:DesignWidth="800"
|
|
x:Name="root"
|
|
Background="White">
|
|
<UserControl.Resources>
|
|
<behaviors:PointListToPointCollectionConverter x:Key="PointListToPointCollectionConverter" />
|
|
<converters:ROITypeToVisibilityConverter x:Key="ROITypeToVisibilityConverter" />
|
|
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
|
</UserControl.Resources>
|
|
<Border BorderBrush="Transparent" BorderThickness="1" ClipToBounds="True">
|
|
<Grid>
|
|
<!-- 图像显示区域 -->
|
|
<Grid x:Name="imageDisplayGrid" ClipToBounds="True">
|
|
<Grid x:Name="transformGrid"
|
|
HorizontalAlignment="Center"
|
|
VerticalAlignment="Center">
|
|
<Grid.LayoutTransform>
|
|
<ScaleTransform x:Name="scaleTransform"
|
|
ScaleX="{Binding ZoomScale, ElementName=root}"
|
|
ScaleY="{Binding ZoomScale, ElementName=root}" />
|
|
</Grid.LayoutTransform>
|
|
<Grid.RenderTransform>
|
|
<TranslateTransform x:Name="translateTransform"
|
|
X="{Binding PanOffsetX, ElementName=root}"
|
|
Y="{Binding PanOffsetY, ElementName=root}" />
|
|
</Grid.RenderTransform>
|
|
|
|
<Canvas x:Name="mainCanvas"
|
|
Width="{Binding CanvasWidth, ElementName=root}"
|
|
Height="{Binding CanvasHeight, ElementName=root}"
|
|
Background="Transparent"
|
|
MouseWheel="Canvas_MouseWheel"
|
|
MouseLeftButtonDown="Canvas_MouseLeftButtonDown"
|
|
MouseLeftButtonUp="Canvas_MouseLeftButtonUp"
|
|
MouseMove="Canvas_MouseMove"
|
|
MouseLeave="Canvas_MouseLeave"
|
|
MouseRightButtonDown="Canvas_MouseRightButtonDown"
|
|
PreviewMouseRightButtonUp="Canvas_PreviewMouseRightButtonUp">
|
|
|
|
<!-- 背景图像 -->
|
|
<Image x:Name="backgroundImage"
|
|
Source="{Binding ImageSource, ElementName=root}"
|
|
Width="{Binding CanvasWidth, ElementName=root}"
|
|
Height="{Binding CanvasHeight, ElementName=root}"
|
|
Stretch="Fill" />
|
|
|
|
<!-- ROI显示 - 只支持多边形 -->
|
|
<ItemsControl ItemsSource="{Binding ROIItems, ElementName=root}">
|
|
<ItemsControl.ItemsPanel>
|
|
<ItemsPanelTemplate>
|
|
<Canvas />
|
|
</ItemsPanelTemplate>
|
|
</ItemsControl.ItemsPanel>
|
|
<ItemsControl.ItemTemplate>
|
|
<DataTemplate>
|
|
<!-- 多边形ROI -->
|
|
<Polygon x:Name="polygonShape"
|
|
behaviors:PolygonPointsBehavior.PointsSource="{Binding Points}"
|
|
Stroke="{Binding Color}"
|
|
StrokeThickness="1"
|
|
Fill="Transparent"
|
|
MouseLeftButtonDown="ROI_MouseLeftButtonDown" />
|
|
</DataTemplate>
|
|
</ItemsControl.ItemTemplate>
|
|
</ItemsControl>
|
|
|
|
<!-- 比例尺:位于图像坐标系内,随 LayoutTransform(缩放)与 RenderTransform(平移)与底图一致 -->
|
|
<Grid
|
|
x:Name="ScaleBarOverlay"
|
|
Canvas.Left="0"
|
|
Canvas.Top="0"
|
|
Width="{Binding CanvasWidth, ElementName=root}"
|
|
Height="{Binding CanvasHeight, ElementName=root}"
|
|
Panel.ZIndex="10000"
|
|
IsHitTestVisible="False"
|
|
Visibility="{Binding ShowScaleBar, ElementName=root, Converter={StaticResource BoolToVisibilityConverter}}">
|
|
<Border
|
|
Margin="0,0,0,12"
|
|
Padding="0"
|
|
HorizontalAlignment="Center"
|
|
VerticalAlignment="Bottom"
|
|
Background="Transparent">
|
|
<StackPanel VerticalAlignment="Bottom" Orientation="Horizontal">
|
|
<!-- 尺身:底线 + 端部刻度 + 内侧无刻度竖线 -->
|
|
<Grid
|
|
x:Name="ScaleBarTrack"
|
|
Height="18"
|
|
MinWidth="8"
|
|
VerticalAlignment="Bottom"
|
|
Width="{Binding ScaleBarLengthPixels, ElementName=root}">
|
|
<Line
|
|
X1="0"
|
|
Y1="16"
|
|
X2="{Binding ScaleBarLengthPixels, ElementName=root}"
|
|
Y2="16"
|
|
Stroke="Red"
|
|
StrokeThickness="2"
|
|
SnapsToDevicePixels="True" />
|
|
<Line
|
|
X1="0"
|
|
X2="0"
|
|
Y1="9"
|
|
Y2="16"
|
|
Stroke="Red"
|
|
StrokeThickness="1.5"
|
|
SnapsToDevicePixels="True" />
|
|
<Line
|
|
X1="{Binding ScaleBarLengthPixels, ElementName=root}"
|
|
X2="{Binding ScaleBarLengthPixels, ElementName=root}"
|
|
Y1="9"
|
|
Y2="16"
|
|
Stroke="Red"
|
|
StrokeThickness="1.5"
|
|
SnapsToDevicePixels="True" />
|
|
<ItemsControl ItemsSource="{Binding ScaleBarMinorTickXs, ElementName=root}">
|
|
<ItemsControl.ItemsPanel>
|
|
<ItemsPanelTemplate>
|
|
<Canvas
|
|
IsItemsHost="True"
|
|
Width="{Binding ScaleBarLengthPixels, ElementName=root}"
|
|
Height="18"
|
|
ClipToBounds="False" />
|
|
</ItemsPanelTemplate>
|
|
</ItemsControl.ItemsPanel>
|
|
<ItemsControl.ItemContainerStyle>
|
|
<Style TargetType="ContentPresenter">
|
|
<Setter Property="Canvas.Left" Value="{Binding}" />
|
|
<Setter Property="Canvas.Top" Value="0" />
|
|
</Style>
|
|
</ItemsControl.ItemContainerStyle>
|
|
<ItemsControl.ItemTemplate>
|
|
<DataTemplate>
|
|
<Line
|
|
X1="0"
|
|
X2="0"
|
|
Y1="11"
|
|
Y2="16"
|
|
Stroke="Red"
|
|
StrokeThickness="1"
|
|
SnapsToDevicePixels="True" />
|
|
</DataTemplate>
|
|
</ItemsControl.ItemTemplate>
|
|
</ItemsControl>
|
|
</Grid>
|
|
<TextBlock
|
|
Margin="6,0,0,0"
|
|
VerticalAlignment="Center"
|
|
FontSize="11"
|
|
FontWeight="SemiBold"
|
|
Foreground="Red"
|
|
Text="{Binding ScaleBarCaption, ElementName=root}" />
|
|
</StackPanel>
|
|
</Border>
|
|
</Grid>
|
|
</Canvas>
|
|
</Grid>
|
|
|
|
<!-- 缩放比例显示 -->
|
|
<TextBlock Text="{Binding ZoomScale, ElementName=root, StringFormat=Zoom Scale: {0:P0}}"
|
|
HorizontalAlignment="Right"
|
|
VerticalAlignment="Bottom"
|
|
Margin="10"
|
|
Padding="5"
|
|
Background="#AA000000"
|
|
Foreground="White"
|
|
FontSize="10" />
|
|
</Grid>
|
|
</Grid>
|
|
</Border>
|
|
</UserControl> |