locked
Why is mouseover not detected on object behind polyline? RRS feed

  • Question

  • I have this XAML for a UserControl with a Polyline in a "triangular" shape:

    <UserControl 
       
       x:Class="Shapes.OtherShapes.MyPolyline"
       
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       
       xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
       xmlns:converters="clr-namespace:Shapes.Converters"
       >
       <UserControl.Resources>
          <converters:MouseOverConverter x:Key="ColorConverter"/>
       </UserControl.Resources>
    
       <Canvas 
          x:Name="LayoutRoot" 
          Background="Transparent" 
          >
          <Polyline 
             Points="50,25 0,100 100,100 50,25"
             StrokeThickness="10"
             Stroke="{Binding MouseOver, Converter={StaticResource ColorConverter}, FallbackValue=Black}"
             Opacity="{Binding Opacity}"
             >
             <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter" >
                   <i:InvokeCommandAction Command="{Binding MouseEnterCommand}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave" >
                   <i:InvokeCommandAction Command="{Binding MouseLeaveCommand}"/>
                </i:EventTrigger>
             </i:Interaction.Triggers>
          </Polyline>
    
       </Canvas>
    
       <UserControl.RenderTransform>
          <TransformGroup>
             <RotateTransform Angle="{Binding Angle}"/>
             <ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}"/>
             <TranslateTransform X="{Binding X}" Y="{Binding Y}"/>
          </TransformGroup>
       </UserControl.RenderTransform>
    
    </UserControl>


    And this XAML for a UserControl with a Circle with a number in it:

    <UserControl 
       
       x:Class="Shapes.NumberedShapes.NumberedCircle"
       
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       
       xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
       xmlns:converters="clr-namespace:Shapes.Converters"
       >
       <UserControl.Resources>
          <converters:MouseOverConverter x:Key="ColorConverter"/>
       </UserControl.Resources>
    
       <Canvas 
          x:Name="LayoutRoot" 
          Background="Transparent" 
          Width="100" 
          Height="100" 
          >
    
          <Ellipse x:Name="Circle1"
             Canvas.Left="-50"
             Canvas.Top="-50"
             Stroke="green" 
             StrokeThickness="3" 
             Fill="{Binding MouseOver, Converter={StaticResource ColorConverter}}"
             Height="100" 
             Width="100"
             Opacity="{Binding Opacity}"
             >
             <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter" >
                   <i:InvokeCommandAction Command="{Binding MouseEnterCommand}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave" >
                   <i:InvokeCommandAction Command="{Binding MouseLeaveCommand}"/>
                </i:EventTrigger>
             </i:Interaction.Triggers>
          </Ellipse>
    
          <Grid 
             Canvas.Left="-40" 
             Canvas.Top="-25" 
             Width="80" 
             Height="50" 
             Background="Transparent" 
             IsHitTestVisible="False"
             >
             <Viewbox >
                <TextBlock Text="{Binding IDNumber, FallbackValue=##}" Foreground="Black" />
             </Viewbox>
          </Grid>
    
       </Canvas>
       
       <UserControl.RenderTransform>
          <TransformGroup>
             <RotateTransform Angle="{Binding Angle}"/>
             <ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}"/>
             <TranslateTransform X="{Binding X}" Y="{Binding Y}"/>
          </TransformGroup>
       </UserControl.RenderTransform>
       
    </UserControl>

    When I position the Polyline partially over top the Circle and I move the mouse from being over nothing to being over the Polyline, the polyline "lights up".  And when I move the mouse to an area off the Polyline line segment, but not yet over the Circle that is behind, the Polyline goes back to its original color.  But if it then goes over the Circle, the Circle doesn't "light up" until I leave the "triangular" area of the Polyline and I'm JUST over the Circle.  In fact, it seems like I actually have to go a little further over in the circle before it lights up.

    Anybody got a clue what is happening?

    Wednesday, October 5, 2016 3:17 PM

All replies

  • I THINK I may have sort of figured it out. I changed the initial XAML for the polyline to so that the polyline was CENTERED around 0,0.  Now I think the RenderTransform is doing the right thing. I suspect there is something about the way the Render was being done that was messing it up if the object was centered initially. 

    Don't understand it at all, but if I center the object, then it rotates and translates okay and the hit test seems to be responding properly for the object behind the Polyline "triangle".

    ... time passes ...

    No, with more testing, something is off.  Seems to depend on positioning and scale or something.  I can make it so that PARTS of the circle behind the triangle seem to respond properly and other parts don't.

    Still open to any clues, I guess

    • Edited by Mark Tiede Wednesday, October 5, 2016 3:29 PM
    Wednesday, October 5, 2016 3:21 PM
  • Hi Mark Tiede,

    Could you please provide more sample code that for MouseOverConverter, MouseEnterCommand and MouseLeveCommand? It can help us reproduce this issue in our side and help us understanding the action how it shows.

    Thanks for your understanding.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 6, 2016 7:44 AM
    Moderator