#679 – Setting IsHitTestVisible to False Prevents Interaction with Controls

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.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #679 – Setting IsHitTestVisible to False Prevents Interaction with Controls

  1. Pingback: Dew Drop – October 30, 2012 (#1,432) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: