Stylus.Synchronize Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Synchronizes the cursor and the user interface.

C#
public static void 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.

C#
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);       
}
C#
void SynchronizeStylus()
{
    Stylus.Synchronize();
    UIElement element = (UIElement)Stylus.DirectlyOver;
    output.Text += "The stylus is over " + element.ToString() + "\r\n";
}

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

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10