WPF层事件分离

时间:2011-01-05 12:12:09

标签: c# wpf canvas

我有一个名为“ canvas ”的最高层,用于显示图片。然后,我尝试将事件menuCanvas_touchDown用于显示我的工作区菜单的名为“ menuCanvas ”的最低层。但是,当我触摸图片时,它会转到menuCanvas_touchDown。它应该在menuCanvas层找到。

<Canvas x:Name="menuCanvas"  
     TouchDown="menuCanvas_TouchDown" TouchUp="menuCanvas_TouchUp" 
    TouchMove="menuCanvas_TouchMove" TouchLeave="menuCanvas_TouchLeave" 
    TouchEnter="menuCanvas_TouchEnter"                 
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  
    Background="Transparent"
    IsManipulationEnabled="True">


    <Canvas x:Name="drawCanvas"  
     TouchDown="drawCanvas_TouchDown" TouchUp="drawCanvas_TouchUp" 
    TouchMove="drawCanvas_TouchMove" TouchLeave="drawCanvas_TouchLeave" 
    TouchEnter="drawCanvas_TouchEnter"                 
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  
    Background="Transparent"
    IsManipulationEnabled="True">
            <Canvas x:Name="canvas"></Canvas>
            </Canvas>
    </Canvas>

alt text

我想触摸图片,而menuCanvas_touchDown事件没有任何反应。 我该如何解决这个问题?我正在尝试使用e.handle,但它打破了对图片的操纵。

由于

修改

有drawCanvas_TouchDown和drawCanvas_TouchUp代码。

private void drawCanvas_TouchDown(object sender, TouchEventArgs e)
    {
        if (state == (int)STATE.Pen)
        {
            if (_activeStrokes.TryGetValue(e.TouchDevice.Id, out stroke))
            {
                FinishStroke(stroke);
                return;
            }

            // Create new stroke, add point and assign a color to it.
            Stroke newStroke = new Stroke();
            newStroke.Color = _touchColor.GetColor();
            newStroke.Id = e.TouchDevice.Id;

            // Add new stroke to the collection of strokes in drawing.
            _activeStrokes[newStroke.Id] = newStroke;
        }

    }private void drawCanvas_TouchUp(object sender, TouchEventArgs e)
    {
        // Find the stroke in the collection of the strokes in drawing.
        if (state == (int)STATE.Pen)
        {
            if (_activeStrokes.TryGetValue(e.TouchDevice.Id, out stroke))
            {
                FinishStroke(stroke);
            }
        }
    }

1 个答案:

答案 0 :(得分:2)

您是否尝试过使用e.OriginalSource?您可以查看活动来源。

if(e.OriginalSource == menuCanvas)
{
    //Your code
}