【问题标题】:Z order in between Image and InkPresenterImage 和 InkPresenter 之间的 Z 顺序
【发布时间】:2009-07-22 03:45:31
【问题描述】:

我有一个包含InkPresenterImage 的CustomControl。该图像有一个AdornerDecorator,因为我计划稍后在图像中添加一个装饰器。我已将ImageCanvas.ZIndex 设置为高于InkPresenter,以便InkPresenter 将绘制在图像上。

问题是,当我尝试从InkPresenter 收集和显示墨水时,笔画会在图像下方绘制。 (我曾经使用 Snoop 检查可视化树,InkPresenterImage 上方)我不确定这是为什么。这里有人知道为什么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。有谁知道为什么会这样?

非常感谢任何帮助。

【问题讨论】:

    标签: wpf image wpf-positioning


    【解决方案1】:

    您正在考虑 z 顺序倒退。较高的值更接近用户,因此值为 2 的图像被绘制在值为 1 的墨水上。

    MSDN

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-29
      • 2017-02-03
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 2011-02-28
      相关资源
      最近更新 更多