我有这个 CustomControl 包含一个InkPresenter和一个Image. 图像有一个AdornerDecorator,因为我计划稍后在图像中添加一个装饰器。我已将 的 设置Canvas.ZIndex为Image高于 ,InkPresenter以便InkPresenter将 绘制在图像上。
问题是,当我尝试从InkPresenter图像下方绘制笔划收集和显示墨水时。(我曾经使用 Snoop 来检查可视化树,并且在InkPresenter上方Image)我不知道为什么会这样。这里有谁知道为什么Image画在上面InkPresenter?任何帮助深表感谢。
我的代码如下:
通用的.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因为我计划稍后将这些事件的处理移至其他类。MouseUpMouseMoveInkPresenter
不幸的是,这些事件没有被捕获,因为Image被绘制在顶部,InkPresenter所以它获取事件而不是InkPresenter. 有谁知道为什么会这样?
任何帮助深表感谢。