I have a custom control with an event handler when you click on it. Everything works and the event get fired right.
AddHandler (cu.MouseLeftButtonDown), AddressOf Me.DoSomething
When the control resizes to show some extra information it expands. It also collapses when the user preses a button. This works alright. But now when I click where the expanded area used to be, it still fires mouse leftbuttondown on that control. I have tried to set IsHitTestVisible to false on the expanded element but it diden’t work. Here’s some xaml…
<UserControl x:Class="MyCustomControl">
<StackPanel>
<Grid>
'Stuff thats always visible
</Grid>
<Border IsHitTestVisible="False" Grid.Row="1" HorizontalAlignment="left" BorderThickness="1" VerticalAlignment="top" x:Name="overView" Background="#EEEEEE" Visibility="Hidden" Margin="-325,-95,0,0" Width="auto" Height="auto" Padding="5,5,5,5" BorderBrush="#999999" CornerRadius="3,3,3,3">
<Border IsHitTestVisible="False" x:Name="myBorder" Margin="1" Width="300" Height="225" BorderThickness="1" BorderBrush="#999999" Background="#DDDDDD" CornerRadius="3,3,3,3" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle IsHitTestVisible="False" x:Name="rtgOverView">
</Rectangle>
</Border>
</Border>
</StackPanel>
</UserControl>
The overview becomes visible when I use this code
overView.Visibility = Windows.Visibility.Visible
And hides when I use this
OverView.Visibility = Windows.Visibility.Collapsed
I fill the rectangle with a visualbrush. This happens when the control is loaded.
rtgOverView.Fill = visual
The overView gets positioned in code behind like this
If x > 350 Then
overView.HorizontalAlignment = Windows.HorizontalAlignment.Left
overView.Margin = New Thickness(-325, -95, 0, 0)
Else
overView.HorizontalAlignment = Windows.HorizontalAlignment.Right
overView.Margin = New Thickness(0, -95, -300, 0)
End If
I cant use another element around my customcontrol since I also use this MouseLeftButtonDown on all different kind of controls.
I can’t figure out how the boundaries on the cu.MouseLeftButtonDown event work to fix this.
There was something weird going on with the size of the stackpanel. It’s like the auto property doesn’t size it smaller. I managed to fix it like this. When the mouse enters I put:
This allows me to show content outside the control.
When the mouse leaves I use:
The clip to bound’s somehow forces the StackPanel to size smaller.