ImageViewerControl.xaml 5.4 KB
<UserControl x:Class="SmartScan.SetControl.WPF.ImageViewerControl"
             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:SmartScan.SetControl.WPF" 
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
            >
    <UserControl.Resources>
        <!-- 按钮样式 -->
        <Style x:Key="ImageViewerButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#3E3E3E"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Padding" Value="10,5"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3">
                            <ContentPresenter HorizontalAlignment="Center" 
                                              VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#555555"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="#222222"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <!-- 图片显示区域 -->
        <!-- 使用Zoombox替换原来的ScrollViewer和Image -->
         <ScrollViewer x:Name="scrollViewer" 
              HorizontalScrollBarVisibility="Auto" 
              VerticalScrollBarVisibility="Auto"
              Grid.Row="0"
              MouseWheel="ScrollViewer_MouseWheel"
              Background="#1E1E1E">
            <Grid x:Name="imageContainer"  HorizontalAlignment="Center" 
          VerticalAlignment="Center">
                <Image x:Name="mainImage" 
               Stretch="Uniform" 
              
               HorizontalAlignment="Center" 
               VerticalAlignment="Center">
                    <Image.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform x:Name="imageScaleTransform" ScaleX="1" ScaleY="1"/>
                        </TransformGroup>
                    </Image.RenderTransform>
                </Image>
                <Canvas x:Name="centerPointsCanvas" IsHitTestVisible="False" HorizontalAlignment="Center"
                VerticalAlignment="Center" />
            </Grid>
        </ScrollViewer>
        <!-- 控制按钮区域 -->
        <Border Grid.Row="1" Background="#2D2D30">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8,0,8">
                <!-- 放大按钮 -->
                <Button x:Name="zoomInButton" 
                        Style="{StaticResource ImageViewerButtonStyle}"
                        Width="40" 
                        Margin="5,0" 
                        Click="ZoomInButton_Click"
                        ToolTip="放大">
                    <TextBlock Text="+" FontSize="16" FontWeight="Bold"/>
                </Button>

                <!-- 缩小按钮 -->
                <Button x:Name="zoomOutButton" 
                        Style="{StaticResource ImageViewerButtonStyle}"
                        Width="40" 
                        Margin="5,0" 
                        Click="ZoomOutButton_Click"
                        ToolTip="缩小">
                    <TextBlock Text="-" FontSize="16" FontWeight="Bold"/>
                </Button>

                <!-- 适应屏幕按钮 -->
                <Button x:Name="fitToScreenButton" 
                        Style="{StaticResource ImageViewerButtonStyle}"
                        Width="40" 
                        Margin="5,0" 
                        Click="FitToScreenButton_Click"
                        ToolTip="适应屏幕">
                    <Viewbox Width="16" Height="16">
                        <Path Data="M21,15H23V17H21V15M21,11H23V13H21V11M23,19H21V21C22.1,21 23,20.1 23,19M13,3H15V5H13V3M21,7H23V9H21V7M21,3V5H23C23,3.9 22.1,3 21,3M1,7H3V9H1V7M17,3H19V5H17V3M17,19H19V21H17V19M3,3C1.9,3 1,3.9 1,5H3V3M9,3H11V5H9V3M5,3H7V5H5V3M1,11H3V13H1V11M3,21V19H1C1,20.1 1.9,21 3,21M3,15H1V17H3V15M9,19H11V21H9V19M13,19H15V21H13V19M5,19H7V21H5V19Z" 
                              Fill="White" 
                              Stretch="Uniform" />
                    </Viewbox>
                </Button>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>