UIElement.IsHitTestVisible Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets whether the contained area of this UIElement can return true values for hit testing.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)


Public Property IsHitTestVisible As Boolean
public bool IsHitTestVisible { get; set; }
<uiElement IsHitTestVisible="bool"/>

Property Value

Type: System.Boolean
true if the contained area of this UIElement can be used for hit-testing; otherwise, false. The default is true.


Dependency property identifier field: IsHitTestVisibleProperty

If this property is set to false, a UIElement will not report any input events, such as MouseLeftButtonDown, and cannot receive focus. A routed input event that was originated by a different object can still route to or through an object in the object tree where IsHitTestVisible is false. The object where IsHitTestVisible is false can choose to handle that event, or can leave it unhandled so that it routes further up the object tree.


The following XAML sets IsHitTestVisible to false on a MediaElement. The scenario here is that the MediaElement is used as a source for a VideoBrush, rather than an intentional part of the UI. In addition to being painted invisible as an element (sets Opacity to 0) the MediaElement should not be active for input events.

<Grid x:Name="LayoutRoot" Background="White">
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*"/>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />

    Source="Butterfly.wmv" IsMuted="True"
    Opacity="0.0" IsHitTestVisible="False" />

  <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"  
    FontFamily="Verdana" FontSize="120" 
    FontWeight="Bold" TextWrapping="Wrap"

    <!-- Paint the text with video. -->
      <VideoBrush SourceName="butterflyMediaElement" Stretch="UniformToFill" />

  <!-- Play -->
  <Button Click="PlayMedia" Grid.Row="1" Grid.Column="0" 
    Width="120" Height="20" Content="Play" />

  <!-- Pause -->
  <Button Click="PauseMedia" Grid.Row="1" Grid.Column="1" 
    Width="120" Height="20" Content="Pause" />

  <!-- Stop -->
    <Button Click="StopMedia" Grid.Row="1" Grid.Column="2" 
      Width="120" Height="20" Content="Stop" />


Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.