WPF层事件分离

发布于 2024-10-10 14:31:25 字数 2304 浏览 0 评论 0原文

我有最高层称为“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);
            }
        }
    }

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>

alt text

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.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);
            }
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-10-17 14:31:25

您尝试过使用 e.OriginalSource 吗?您可以检查事件来源。

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

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

if(e.OriginalSource == menuCanvas)
{
    //Your code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文