WPF question-- is an Image blocking my Rectangle from events?


J

Jim Bancroft

Hi everyone,

I have a WPF application that mimics an MP3 player. There's an image of the
player placed into the only square of a 1 row/ 1 column grid. In the same
grid I also have rectangles and buttons, aligned precisely (I didn't design
the XAML).

The image is sized to fit the entire window. I can receive mouse events
from the buttons, but not the rectangles. I'm at a loss to understand why.
Here's a simplified version of the XAML I'm using:

<Window
Title="Window"
Width="226" Height="493" AllowDrop="True" Background="{x:Null}"
AllowsTransparency="True" WindowStyle="None">

<Grid x:Name="DocumentRoot">
<Image Margin="0,0,0,0" x:Name="pod" Source="iPod.png"
d:IsLocked="True" Width="226" Height="493"/>
<Rectangle MouseUp="my_MouseLeftButtonUp" Stroke="{x:Null}"
Height="8.5160149093436" x:Name="progress_Copy"
Margin="44.19,127.48,48.80,0" VerticalAlignment="Top"/>
<Button Opacity="0" Cursor="Hand" Margin="91.92,184.801,98.18,0"
x:Name="closeButton" VerticalAlignment="Top" Height="18.88"
Content="Button" ToolTip="Close the player" Click="closer" />
<Button Opacity="0" Cursor="Hand" HorizontalAlignment="Right"
Margin="0,225.09,62.292,245." x:Name="muteButton" Width="24.87"
Content="Button" ToolTip="Mute toggle" Click="muter"/>
</Grid>
</Window>

As I said, this is simplified, but it gets the idea across. Note in the
Rectangle above I have a MouseUp event handler. It doesn't work with the
rectangle, but if I used a MouseUp handler on the buttons, it will fire off
no sweat. Same goes for the image, if I put a MouseUp handler in it, it
fires off when I click.

Is there something blazingly obvious I've missed? As you can see above the
Image takes up the entire window. Is it somehow blocking the rectangle from
receiving events? If so, why aren't the buttons having the same problem?

Also, I hope I'm posting this to the appropriate forums: I couldn't find any
WPF-specific ones. Please accept my apologies if this went to the wrong
place and if you could point me to a better forum, I'd appreciate it.
Thanks!
 
Ad

Advertisements

Ad

Advertisements

J

Jim Bancroft

Correction part II-- my reply above was for a different problem, having to
do with textboxes not respecting the AllowDrop directive. One day I'll get
all this right...

carry on
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top