【发布时间】:2009-07-22 03:45:31
【问题描述】:
我有一个包含InkPresenter 和Image 的CustomControl。该图像有一个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。有谁知道为什么会这样?
非常感谢任何帮助。
【问题讨论】:
标签: wpf image wpf-positioning