ערוך

שתף באמצעות


Stylus.Synchronize Method

Definition

Synchronizes the cursor and the user interface.

public:
 static void Synchronize();
public static void Synchronize ();
static member Synchronize : unit -> unit
Public Shared Sub Synchronize ()

Examples

The following example demonstrates how to get the element that is under the cursor. Calling Synchronize ensures that DirectlyOver returns the correct element.

void AnimateButton()
{
    TranslateTransform buttonTransform = new TranslateTransform(0, 0);
    button1.RenderTransform = buttonTransform;

    // Animate the Button's position.
    DoubleAnimation myDoubleAnimation = new DoubleAnimation();
    myDoubleAnimation.From = 0;
    myDoubleAnimation.By = 100;
    myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
    myDoubleAnimation.AutoReverse = true;
    myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

    buttonTransform.BeginAnimation(TranslateTransform.XProperty, myDoubleAnimation);       
}
Sub AnimateButton() 
    Dim buttonTransform As New TranslateTransform(0, 0)
    button1.RenderTransform = buttonTransform
    
    ' Animate the Button's position.
    Dim myDoubleAnimation As New DoubleAnimation()
    myDoubleAnimation.From = 0
    myDoubleAnimation.By = 100
    myDoubleAnimation.Duration = New Duration(TimeSpan.FromSeconds(5))
    myDoubleAnimation.AutoReverse = True
    myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever
    
    buttonTransform.BeginAnimation(TranslateTransform.XProperty, myDoubleAnimation)

End Sub
void SynchronizeStylus()
{
    Stylus.Synchronize();
    UIElement element = (UIElement)Stylus.DirectlyOver;
    output.Text += "The stylus is over " + element.ToString() + "\r\n";
}
Sub SynchronizeStylus()

    Stylus.Synchronize()
    Dim element As UIElement = CType(Stylus.DirectlyOver, UIElement)
    output.Text += "The stylus is over " + element.ToString() & vbCr & vbLf

End Sub

Remarks

Applications may need to determine the element on which the cursor is located. If the application uses animation, the DirectlyOver method might return an element that has moved out from under the cursor. Call Synchronize to be sure that DirectlyOver returns the proper element.

Applies to