2009-07-22 27 views
0

これは私の質問hereのフォローアップです。 InkPresenterがユーザーに最も近いにもかかわらず、MouseDown/MouseMove/MouseUpイベントがImage要素で受信されたようです。なぜ誰がそれが分かっていますか?Zオーダーとイベント処理wpf

編集:申し訳ありませんが、私は質問を明確にしなかった場合:

私はImageの兄弟である、InkPresenterにイベントハンドラを貼られています。 InkPresenterZIndexを2に設定しました(他の要素はZIndexとして0を持っています)。私はイベントハンドラがなぜ画像によって受信されるのか分からない。私は、最高のZIndexを持つ要素がユーザーに最も近いと仮定しました。したがって、ユーザによって生成されたMouseDown/MouseMove/MouseUpイベントを受信するのは初めてですが、この場合はImageがイベントを受信します。次のように

私のコードは次のとおりです。

CustomImage.cs

[TemplatePart(Name="PART_InkPresenter",Type=typeof(InkPresenter))] 
[TemplatePart(Name="PART_Image",Type=typeof(Image))] 
public class CustomImage : Control 
{ 
    public static DependencyProperty SourceProperty; 

    public string Source 
    { 
     get { return (string)GetValue(SourceProperty); } 
     set { SetValue(SourceProperty,value); } 
    } 

    private InkPresenter _presenter; 
    private Image _image; 


    static CustomImage() 
    { 
     DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomImage), 
       new FrameworkPropertyMetadata(typeof(CustomImage))); 

     SourceProperty = DependencyProperty.Register("Source", 
       typeof(string), typeof(CustomImage)); 
    } 

    public override void OnApplyTemplate() 
    { 
     base.OnApplyTemplate(); 
     _presenter = base.GetTemplateChild("PART_InkPresenter") as InkPresenter; 
     _image = base.GetTemplateChild("PART_Image") as Image; 

     _presenter.MouseDown += new MouseButtonEventHandler(_presenter_MouseDown); 
     _presenter.MouseMove += new MouseEventHandler(_presenter_MouseMove); 
     _presenter.MouseUp += new MouseButtonEventHandler(_presenter_MouseUp); 


    } 

    void _presenter_MouseUp(object sender, MouseButtonEventArgs e) 
    { 
     // ... 
    } 

    void _presenter_MouseMove(object sender, MouseEventArgs e) 
    { 
     // ... 
    } 

    void _presenter_MouseDown(object sender, MouseButtonEventArgs e) 
    { 
     // ... 
    } 

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:CustomImage"> 
    <Style TargetType="{x:Type local:CustomImage}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:CustomImage}"> 
        <ControlTemplate.Resources> 
         <local:StringtoImageSource x:Key="ImageSourceConverter"/> 
        </ControlTemplate.Resources> 
        <Canvas Width="{TemplateBinding Width}" 
          Height="{TemplateBinding Height}">    
         <Image x:Name="PART_Image" 
           Width="{TemplateBinding Width}" 
           Height="{TemplateBinding Height}" Source="{Binding 
           RelativeSource={RelativeSource TemplatedParent}, 
           Path=Source, 
           Converter={StaticResource ImageSourceConverter}}"/> 
         <InkPresenter Canvas.ZIndex="2" 
           x:Name="PART_InkPresenter" 
           Width="{TemplateBinding Width}" 
           Height="{TemplateBinding Height}"/> 
        </Canvas> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

答えて

1

彼らは何か他のものによって処理されていないので?誰もイベントを処理しない場合(e.Handledtrue)、それらはWPFビジュアルツリーを横断し続けます。それは、ルーティングされたイベントがするはずのものです。

実際に何かを処理する必要があるかどうかを知るための十分な情報はありませんでした。

+0

返信ありがとうございますケント:)質問を更新しました – Nilu

関連する問題