在WPF中放大图像

Ida*_*nis 2 c# wpf xaml image image-enlarge

我有一个WPF应用程序,它检查某个父目录中的新图像,如果有新图像,它会切换当前显示的图像(我有6个图像).

我想添加一个功能,允许用户点击其中一个图像,然后点击,将出现一个"新"窗口,显示图像放大,屏幕上任何地方的另一次点击将退出此放大和把焦点放回到其他(6)图像.

那可能吗?我尝试谷歌搜索,zoom image wpf但发现只有mouse-drag相关的解决方案.

我也试过使用,viewport但也没有那么好用.

更新 - XAML

<Grid Grid.Row="0">
        <GroupBox  x:Name="AccuracyGraphsGroupBox" Header="Accuracy" Foreground="Red">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.5*" />
                    <ColumnDefinition Width="0.5*" />
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Width="Auto" Height="Auto" Stretch="Fill" x:Name="AccuracyPicBox" MouseUp="AccuracyPicBox_OnMouseUp"></Image>
                <Image Grid.Column="1" Width="Auto" Height="Auto" Stretch="Fill" x:Name="AccuracyPerioPicBox" MouseUp="AccuracyPerioPicBox_OnMouseUp"></Image>
            </Grid>
        </GroupBox>
    </Grid>
Run Code Online (Sandbox Code Playgroud)

She*_*dan 7

正如评论中提到的那样,你最好的选择是使用a ToolTip弹出你的全尺寸图像.有数据绑定的一个小问题,Image.Source从原来的价值Image在你的ToolTip,因为他们是不正常的UI视觉树的一部分,并在自己的树存在.但是,我们可以通过使用ToolTip.PlacementTarget属性来克服这个问题:

<Image Name="Image" Source="/WpfApplication1;component/Images/Tulips.jpg" Height="100"
    Stretch="Uniform">
    <Image.ToolTip>
        <ToolTip DataContext="{Binding PlacementTarget, 
            RelativeSource={RelativeSource Self}}">
            <Border BorderBrush="Black" BorderThickness="1" Margin="5,7,5,5">
                <Image Source="{Binding Source}" Stretch="None" />
            </Border>
        </ToolTip>
    </Image.ToolTip>
</Image>
Run Code Online (Sandbox Code Playgroud)

当然,您可以Binding Path在两个Image.Source属性中使用相同的内容,但我从不喜欢重复代码.