开发者

WPF layer event separation

开发者 https://www.devze.com 2023-02-02 20:02 出处:网络
I have the highest layer called \"canvas\" which is used to display picture. Then, I\'m trying to use event menuCanvas_touchDown to lowest layer called \"menuCanvas\" which show my workspace menu. How

I have the highest layer called "canvas" which is used to display picture. Then, I'm trying to use event menuCanvas_touchDown to lowest layer called "menuCanvas" which show my workspace menu. However, when I touch the picture, it go to menuCanvas_touchDown. It should be found at the menuCanvas layer.

<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>

WPF layer event separation

I want to touch picture and nothing happen to menuCanvas_touchDown event. How do I solve this problem? I'm trying to use e.handle, but it break the manipulation of the picture.

Thanks

Edit:

There are drawCanvas_TouchDown and drawCanvas_TouchUp code.

private void drawCanvas_TouchDown(object sender, TouchEventArgs e)
    {
        if (state == (int)STATE.Pen)
        {
            if (_activeStrokes.TryGetV开发者_StackOverflow社区alue(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);
            }
        }
    }


Have you try to use e.OriginalSource? You can check source of event.

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

精彩评论

暂无评论...
验证码 换一张
取 消