Поделиться через


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)

Syntax

'Declaration
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.

Remarks

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.

Examples

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">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*"/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>

  <MediaElement 
    x:Name="butterflyMediaElement" 
    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"
    Text="Video">

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

  <!-- 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" />

</Grid>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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