2009-07-22 38 views
1

我有這個CustomControl其中包含InkPresenterImage。該圖像有一個AdornerDecorator,因爲我打算稍後將圖像添加到圖像中。我已將ImageCanvas.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> 

我附上了MouseDownMouseUpMouseMove等事件給InkPresenter,我打算將這些事件的處理到其他班級以後。

不幸的是,這些事件不會被捕獲,因爲Image繪製在InkPresenter之上,因此它獲取事件而不是InkPresenter。有誰知道這可能是爲什麼?

任何幫助,非常感謝。

回答

1

您正在考慮z順序倒退。較高的值更接近用戶,從而與價值2圖像繪製在用價值油墨1

MSDN

+0

感謝:d我總是得到的是另一種方式圓...:S – Nilu 2009-07-22 04:44:43