我正在使用图片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;
}
}
答案 0 :(得分:0)
您可以尝试使用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();
}