StylusDevice.Synchronize 方法

定義

同步處理游標和使用者介面。Synchronizes the cursor and the user interface.

public:
 void Synchronize();
[System.Security.SecurityCritical]
public void Synchronize ();
member this.Synchronize : unit -> unit
Public Sub Synchronize ()
屬性

範例

下列範例示範如何傳回游標下的元素。The following example demonstrates how to return an element that is under the cursor. 呼叫Synchronize可確保DirectlyOver會傳回正確的元素。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 SynchronizeCurrentStylus()
{
    StylusDevice currentStylus = Stylus.CurrentStylusDevice;

    currentStylus.Synchronize();
    UIElement element = (UIElement) currentStylus.DirectlyOver;
    output.Text += "The stylus is over " + element.ToString() + "\r\n";
}
Sub SynchronizeCurrentStylus()

    Dim currentStylus As StylusDevice = Stylus.CurrentStylusDevice

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

End Sub

備註

應用程式可能需要找出游標所在位置的元素。Applications may need to locate the element that the cursor is positioned over. 如果應用程式使用動畫, 此DirectlyOver方法可能會傳回已從游標下移出的元素。If the application uses animation, the DirectlyOver method might return an element that has moved out from under the cursor. 呼叫SynchronizeDirectlyOver確定會傳回適當的元素。Call Synchronize to be sure that DirectlyOver returns the proper element.

適用於