Image 和 InkPresenter 之间的 Z 顺序
我有这个 CustomControl,其中包含一个 InkPresenter
和一个 Image
。 该图像有一个 AdornerDecorator
因为我计划稍后向图像添加装饰器。 我已将 Image
的 Canvas.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>
我已将 MouseDown
、MouseUp
、MouseMove
等事件附加到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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在向后考虑 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