Perhaps I'm having a Post-Ballmer-Peak Moment. I'm hoping that someone can help point out the obvious to me.
Why does this code generate a context menu on right click:
<Canvas Background="Transparent">
<Canvas.ContextMenu>
<ContextMenu>
<TextBlock>WTF?</TextBlock>
</ContextMenu>
</Canvas.ContextMenu>
</Canvas>
And this code doesn't generate a context menu:
<Canvas>
<Canvas.ContextMenu>
<ContextMenu>
<TextBlock>WTF?</TextBlock>
</ContextMenu>
</Canvas.ContextMenu>
</Canvas>
It's because the Transparent
brush allows an area to be hittable and thus receive and respond to mouse clicks, whereas the default null
brush doesn't. In other words, without any brush defined, the region becomes "hollow" and clicks pass through; with a brush defined (even a transparent one), they are "solid" and clicks can be received.
See this helpful article on WPF brushes for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With