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.

4

1 回答 1

1

我不确定你的拖放代码,但也许你可以使用触发器,只有当你拖动一个项目时,它IsHitTestVisible才是False真正的。

作为旁注,我过去在使用 WPF 的内置DragDrop功能和命中测试时遇到过问题。我发现使用 MouseEvents 更简单,例如用于拖动的跟踪MouseEnter/事件MouseLeave

于 2011-09-30T12:50:36.777 回答