StylusDevice.Synchronize 方法

定义

同步光标和用户界面。

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

示例

以下示例演示如何返回光标下的元素。 调用 Synchronize 可确保 DirectlyOver 返回正确的元素。

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

注解

应用程序可能需要定位光标所在的元素。 如果应用程序使用动画,该方法 DirectlyOver 可能会返回从光标下移出的元素。 调用 Synchronize 以确保 DirectlyOver 返回正确的 元素。

适用于