#679 – Setting IsHitTestVisible to False Prevents Interaction with Controls
October 30, 2012 1 Comment
When you set the IsHitTestVisible property to false for a user interface element, it will no longer respond to mouse input and will not fire mouse-related events.
With IsHitTestVisible set to false, you therefore can’t use the mouse to interact with a user interface element at all. In the example below, we can’t use the mouse to give the elements focus or to click or select any of them.
<StackPanel> <Button Content="You can't Click this" HorizontalAlignment="Center" Margin="5" Click="Button_Click_1" IsHitTestVisible="False"/> <TextBox Text="You can't Edit this" HorizontalAlignment="Center" Margin="5" IsHitTestVisible="False"/> <CheckBox Content="You can't Check this" HorizontalAlignment="Center" Margin="5" IsHitTestVisible="False"/> <ComboBox HorizontalAlignment="Center" Margin="5" SelectedIndex="0" IsHitTestVisible="False"> <ComboBox.Items> <ComboBoxItem Content="You can't Select this"/> <ComboBoxItem Content="Or this"/> </ComboBox.Items> </ComboBox> </StackPanel>
Notice, however, that you can still interact with the elements using the keyboard. For example, you can tab to the Button and then press Enter to trigger its Click event.
Pingback: Dew Drop – October 30, 2012 (#1,432) | Alvin Ashcraft's Morning Dew