Exporter (0) Imprimer
Développer tout
Développer Réduire

HitTestResultCallback, délégué

WPF invokes the HitTestResultCallback to report hit test intersections to the user.

Espace de noms: System.Windows.Media
Assembly : PresentationCore (dans presentationcore.dll)

public delegate HitTestResultBehavior HitTestResultCallback (
	HitTestResult result
)
/** @delegate */
public delegate HitTestResultBehavior HitTestResultCallback (
	HitTestResult result
)
Dans XAML, vous pouvez utiliser des délégués, mais vous ne pouvez pas définir vos propres délégués.

Paramètres

result

The HitTestResult value that represents a visual object that is returned from a hit test.

The hit test callback method defines the actions that you perform when a hit test is identified on a particular visual object in the visual tree. After you perform the actions, you return a HitTestResultBehavior value that determines whether to continue the enumeration of any other visual objects.

The following example shows how to invoke HitTest by using a HitTestResultCallback value. The corresponding hit test callback method is also defined.

// Capture the mouse event and hit test the coordinate point value against
// the child visual objects.
void MyVisualHost_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    // Retreive the coordinates of the mouse button event.
    Point pt = e.GetPosition((UIElement)sender);

    // Initiate the hit test by setting up a hit test result callback method.
    VisualTreeHelper.HitTest(this, null, new HitTestResultCallback(myCallback), new PointHitTestParameters(pt));
}

// If a child visual object is hit, toggle its opacity to visually indicate a hit.
public HitTestResultBehavior myCallback(HitTestResult result)
{
    if (result.VisualHit.GetType() == typeof(DrawingVisual))
    {
        if (((DrawingVisual)result.VisualHit).Opacity == 1.0)
        {
            ((DrawingVisual)result.VisualHit).Opacity = 0.4;
        }
        else
        {
            ((DrawingVisual)result.VisualHit).Opacity = 1.0;
        }
    }

    // Stop the hit test enumeration of objects in the visual tree.
    return HitTestResultBehavior.Stop;
}

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

.NET Framework

Prise en charge dans : 3.0

Ajouts de la communauté

AJOUTER
Afficher:
© 2015 Microsoft