Image 和 InkPresenter 之间的 Z 顺序

发布于 2024-07-27 20:06:09 字数 2504 浏览 8 评论 0原文

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

问题是,当我尝试从 InkPresenter 收集和显示墨迹时,笔划会绘制在图像下方。 (我曾经使用 Snoop 检查视觉树,并且 InkPresenter 位于 Image 之上)我不确定这是为什么。 这里有人知道为什么 Image 绘制在 InkPresenter 之上吗? 任何帮助深表感谢。

我的代码如下:

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>

我已将 MouseDownMouseUpMouseMove 等事件附加到InkPresenter 因为我计划稍后将这些事件的处理移至其他类。

不幸的是,这些事件不会被捕获,因为 Image 是在 InkPresenter 之上绘制的,因此它获取事件而不是 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.

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.

My code is as follows:

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>

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.

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?

Any help is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤星 2024-08-03 20:06:09

您正在向后考虑 z 顺序。 值越高,离用户越近,因此值 2 的图像将绘制在值 1 的墨水上。

请参阅 MSDN

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.

See MSDN

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文