共用方式為


Stylus.Synchronize 方法

定義

同步處理游標和使用者介面。

public:
 static void Synchronize();
public static void Synchronize ();
static member Synchronize : unit -> unit
Public Shared 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 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

備註

應用程式可能需要判斷游標所在的專案。 如果應用程式使用動畫, DirectlyOver 方法可能會傳回已從游標下方移出的專案。 呼叫 Synchronize 以確定 DirectlyOver 傳回適當的專案。

適用於