Image和InkPresenter之间的Z顺序 [英] Z order in between Image and InkPresenter

查看:157
本文介绍了Image和InkPresenter之间的Z顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个CustomControl,其中包含 InkPresenter 图像。该图片有一个 AdornerDecorator ,因为我打算稍后在图片中添加一个装饰器。我已将 Image Canvas.ZIndex 设置为高于 InkPresenter 以便在Image上绘制 InkPresenter

I have this CustomControl which contains an InkPresenter and an Image. The image has an AdornerDecorator as I plan to add an adorner to the image later on. I have set the Canvas.ZIndex of the Image to be higher than the InkPresenter so that the InkPresenter will be drawn over the Image.

问题在于,当我尝试从 InkPresenter 收集并显示墨迹时,笔划会在图像下方绘制。 (我以前使用Snoop检查可视树, InkPresenter 高于图像)我不确定为什么会这样。有没有人知道为什么 Image 是在 InkPresenter 之上绘制的?非常感谢任何帮助。

The problem is that when I try to collect and display ink from the InkPresenter the strokes are drawn underneath the image. (I have used to check the visual tree using Snoop and the InkPresenter is above the Image) I'm not sure why this is. Does anyone here know why the Image is drawn on top of the InkPresenter? Any help is much appreciated.

我的代码如下:

Generic.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:HotSpotImage">
    <Style TargetType="{x:Type local:HotSpotImage}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:HotSpotImage}">
                    <ControlTemplate.Resources>
                        <local:StringtoImageSource x:Key="ImageSourceConverter"/>

                    </ControlTemplate.Resources>
                    <Canvas Width="{TemplateBinding Width}" 
                            Height="{TemplateBinding Height}">    
                        <InkPresenter Canvas.ZIndex="1"  
                                      x:Name="PART_InkPresenter"
                                      Width="{TemplateBinding Width}" 
                                      Height="{TemplateBinding Height}"/>
                        <Image Canvas.ZIndex="2"  x:Name="PART_Image" 
                               Width="{TemplateBinding Width}" 
                               Height="{TemplateBinding Height}" Source="{Binding 
                                RelativeSource={RelativeSource TemplatedParent}, 
                                Path=Source, 
                                Converter={StaticResource ImageSourceConverter}}"/>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

我附上 MouseDown MouseUp MouseMove 等事件到 InkPresenter 因为我打算搬家稍后将这些事件处理到其他类。

I have attached the MouseDown, MouseUp, MouseMove etc events to the InkPresenter as I plan to move the handling of these events to other classes later on.

不幸的是,这些事件没有被捕获,因为 Image InkPresenter 之上绘制,因此它获取事件而不是 InkPresenter 。有谁知道为什么会这样?

Unfortunately these events don't get captured because the Image is drawn on top of the InkPresenter so it gets the events rather than the InkPresenter. Does anyone know why this may be?

非常感谢任何帮助。

推荐答案

您正在考虑向后调整z顺序。较高的值更接近用户,因此值为2的图像将通过值为1的墨水绘制。

You are thinking about z-order backwards. The higher values are closer to the user, thus the image with value 2 is drawn over the ink with value 1.

请参阅 MSDN

这篇关于Image和InkPresenter之间的Z顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆