Reputation: 12870
A simple silverlight app:
<Grid x:Name="LayoutRoot">
<Canvas x:Name="C1" MouseLeftButtonDown="C1_MouseLeftButtonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas x:Name="C2" MouseLeftButtonDown="C2_MouseLeftButtonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Rectangle x:Name="R1" Fill="AliceBlue" Height="40" Width="60"/>
</Canvas>
</Canvas>
</Grid>
Why do the Canvas mouse event handlers get called only when I click in the Rectangle control, and not in the empty Canvas?
Thanks.
Upvotes: 1
Views: 400
Reputation: 189447
You need to give the Canvas a background brush to give the Canvas a surface on which to detect a mouse.
<Grid x:Name="LayoutRoot">
<Canvas x:Name="C1" Background="White" MouseLeftButtonDown="C1_MouseLeftButtonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas x:Name="C2" MouseLeftButtonDown="C2_MouseLeftButtonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Rectangle x:Name="R1" Fill="AliceBlue" Height="40" Width="60"/>
</Canvas>
</Canvas>
</Grid>
Upvotes: 4