开发者

disable event-bubbling c# wpf

开发者 https://www.devze.com 2022-12-24 01:11 出处:网络
I\'m having the following problem: When I got two labels into each other: <Label x:Name=\"First\" MouseUp=\"Label_MouseUp\">

I'm having the following problem:

When I got two labels into each other:

<Label x:Name="First" MouseUp="Label_MouseUp">
    <Label x:Name="Second" MouseUp="Label_MouseUp_1">This is a label into another label</Labe开发者_开发技巧l>
</Label>

And the following code:

private void Label_MouseUp(object sender, MouseButtonEventArgs e)
{
    Console.WriteLine("Do NOT show me");
}

private void Label_MouseUp_1(object sender, MouseButtonEventArgs e)
{
    Console.WriteLine("Show me");
}

When i click "Second", I want it to trigger only "Label_MouseUp_1". But in my console i get:

Show me

Do NOT show me

Is there a way to turn off the bubbling events?

(also, "First" has to be clickable, so removing the event there doesn't solve the problem)

Thnx


I don't have the docs right in front of me, but I think if you mark the MouseButtonEventArgs object as Handled it stops the event from going up the chain.

Should be as simple as

e.Handled = true;

Please somebody correct me if I am wrong about this.

0

精彩评论

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