gpt4 book ai didi

c# - WPF层事件分离

转载 作者:太空宇宙 更新时间:2023-11-03 11:41:37 25 4
gpt4 key购买 nike

我有一个名为“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);
}
}
}

最佳答案

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

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

关于c# - WPF层事件分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4603851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com