我有這個CustomControl其中包含InkPresenter
和Image
。該圖像有一個AdornerDecorator
,因爲我打算稍後將圖像添加到圖像中。我已將Image
的Canvas.ZIndex
設置爲高於InkPresenter
,以便將InkPresenter
繪製在圖像上。圖像和InkPresenter之間的Z順序
問題是,當我嘗試從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
。有誰知道這可能是爲什麼?
任何幫助,非常感謝。
感謝:d我總是得到的是另一種方式圓...:S – Nilu 2009-07-22 04:44:43