2

I have a grid that contains 3 rows, one of which contains a TextBox thats can be edited. The grid sits inside a paretn that provides drag functionality to enable it to moved around a canvas. In order to enable this, i need to set IsHitTestVisible to false, in order to allow the mouse click to passed through to the parent object.

The problem is, when i do this, i cant select the textbox in the grid, even if the hit test visible is set to True;

<Grid Background="{StaticResource NodeBackground}" IsHitTestVisible="True">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="2*"/>
                            <RowDefinition Height="1*"/>
                            <RowDefinition Height="2*"/>
                        </Grid.RowDefinitions>
                        <TextBox Text="{Binding Data}" Foreground="White" Background="Transparent" FontFamily="Consolas" FontSize="15" TextAlignment="Center" Grid.Row="1" BorderThickness="0" />
                    </Grid>

Is it possible to set the hit test property on a per-row basis, so if either of the two empty rows were hit, they would continue to pass the click onto the parent container, but still be able to select the textbox in the middle row?

Cheers.

H.B.
  • 166,899
  • 29
  • 327
  • 400
richzilla
  • 40,440
  • 14
  • 56
  • 86
  • Why do you need `IsHitTestVisible`? By the virtue of [events bubbling](http://msdn.microsoft.com/en-us/library/ms742806.aspx#routing_strategies) your Grid's parent will get all mouse events of the Grid that where not handled by the `TextBox`. Am I missing something? – alpha-mouse Sep 30 '11 at 12:54
  • Share your drag drop logic. Because normally this is supposed to work as you expect it to, just as @alpha-mouse said. – Zahid Sattar Sep 30 '11 at 13:20

1 Answers1

1

I'm not certain your Drag/Drop code, but perhaps you can use a Trigger, where IsHitTestVisible is False only if you are dragging an item, and the rest of the time it's True.

As a side note, I've had issues in the past using WPF's built-in DragDrop functionality and hit testing. I find it much simpler to use MouseEvents instead, such as tracking MouseEnter/MouseLeave events for dragging

Rachel
  • 130,264
  • 66
  • 304
  • 490