[英]How can i set the time for Image on_hold behaviour?
我正在使用圖像on_hold
行為來執行任務。 我為此設置了一個計時器,我將時間設置為5秒鍾,如果用戶按住該圖像5秒鍾,則頁面將導航。 現在我只希望在用戶按住圖像5秒鍾的情況下,然后在任何情況下(例如1秒鍾或2秒鍾)不進行頁面導航,然后將其刪除。如何設置圖像on_hold
計時器?
Public mainpage()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += (s, e) =>
{
var frame = App.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/Second Page.xaml", UriKind.Relative));
timer.Stop();
};
}
private void Image_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
// want to set timer here either for story board or for on_hod behaviour
myStoryboard.Begin();
NewMedia.Play();
tick();
}
private void tick()
{
counter--;
if (counter <=0)
{
timer.Start();
counter = 5;
}
else
{
counter = 5;
}
}
您可以嘗試結合使用ManipulationStarted和ManupulationCompleted事件而不是Hold
事件。 將Timer
間隔設置為5秒:
timer.Interval = TimeSpan.FromSeconds(5);
用戶開始保存圖像后,啟動Timer
:
private void Image_ManipulationStarted(object sender, ManipulationCompletedEventArgs e)
{
myStoryboard.Begin();
NewMedia.Play();
timer.Start();
}
然后,如果用戶在5秒鍾之前停止持有圖像,請停止Timer
:
private void Image_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
timer.Stop();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.