1

アクション (アプリケーション バー ボタンを有効にする) を実行する前に、アプリケーションを一時停止する必要がありますが、これを実現する最善の方法がわかりません。基本的に別のスレッドで多くの処理が行われていますが、その後 UI が更新されます。UI が更新されたら、ピボット コントロールを特定のピボット アイテムまでスクロールします。アプリケーション バー ボタンを有効にする前に、約 1 秒間一時停止するか、ピボット コントロールの前のピボット項目にスクロールするのに時間がかかります。どうすればこれを達成できますか? 私がこれまでに持っているものは次のとおりです

// Show image and scroll to start page if needed
if (Viewport != null)
{
    Viewport.Source = result;
    if (editPagePivotControl != null && editPagePivotControl.SelectedIndex != 0)
    {
    //Here is where the pivot control is told to move to the first item
    // (from the second which it will be on before this happens)
        editPagePivotControl.SelectedIndex = 0;
    }
    //A flag to determine whether the app bar button should be enabled
    //How to pause for the time it takes to finish moving
    // to the first pivot item?         
    if (_wasEdited)
        ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true;
    }
4

1 に答える 1

1

System.Windows.Threading.DispatcherTimerを使用して、これを試してください。

if (_wasEdited)
{
   DispatcherTimer t = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher);
   t.Tick += new EventHandler((o,e) => 
     ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true;
   t.Interval = TimeSpan.FromMilliseconds(1000);
   t.Start();
}

これは 1000 ミリ秒待機し、UI スレッドに戻り (コンストラクターで設定DispatcherしたDispatcherTimerため)、アプリケーション バーを有効にします。

これを頻繁に行う場合は、タイマーをクラスのメンバーにすることを検討してください。

于 2013-10-06T22:08:15.903 に答える