开发者

Make hit test visible property different for grid rows

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 H开发者_如何转开发eight="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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜