Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何设置图像保留行为的时间?_C#_Xaml_Windows Phone 8 - Fatal编程技术网

C# 如何设置图像保留行为的时间?

C# 如何设置图像保留行为的时间?,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我正在使用图像保持行为来执行任务。我为它设置了一个计时器,在这个计时器中,我设置了5秒的时间,若用户持有该图像5秒,页面将导航。现在,我只想在用户按住图像5秒的情况下,页面导航不在任何条件下,如用户按住1秒或2秒,然后删除。我如何设置图像的计时器保持 Public mainpage() { InitializeComponent(); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds

我正在使用图像
保持
行为来执行任务。我为它设置了一个计时器,在这个计时器中,我设置了5秒的时间,若用户持有该图像5秒,页面将导航。现在,我只想在用户按住图像5秒的情况下,页面导航不在任何条件下,如用户按住1秒或2秒,然后删除。我如何设置图像
的计时器保持

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;
    }
}
Public主页()
{ 
初始化组件();
计时器=新调度程序();
timer.Interval=TimeSpan.FromSeconds(1);
计时器.勾号+=(s,e)=>
{
var frame=App.Current.RootVisual作为PhoneApplicationFrame;
导航(新Uri(“/Second Page.xaml”,UriKind.Relative));
timer.Stop();
};
}
私有无效图像保存(对象发送方,System.Windows.Input.GestureEventArgs e)
{     
//想在这里为故事板或现场行为设置计时器吗
myStoryboard.Begin();
NewMedia.Play();
勾选();
}
私人空白勾号()
{
计数器--;

如果(计数器您可以尝试使用和事件的组合,而不是
保持
事件。将
计时器
间隔设置为5秒:

timer.Interval = TimeSpan.FromSeconds(5);
当用户开始持有图像时,启动
计时器

private void Image_ManipulationStarted(object sender, ManipulationCompletedEventArgs e)
{
    myStoryboard.Begin();
    NewMedia.Play();
    timer.Start();
}
private void Image_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
    timer.Stop();
}
然后,如果用户在5秒钟之前停止持有图像,则停止
计时器

private void Image_ManipulationStarted(object sender, ManipulationCompletedEventArgs e)
{
    myStoryboard.Begin();
    NewMedia.Play();
    timer.Start();
}
private void Image_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
    timer.Stop();
}

我很感激你的回答。但我没有得到我的结果,5秒后它仍然会移动,用户保持或不保持。如果用户在5秒前停止保持图像,然后计时器停止,我无法使用条件。当我使用操作完成时,这意味着用户移动保持。plzz建议不理解最后一部分:“…这意味着用户移动保持”。我希望在用户停止按住时触发操纵完成,无论他按住了多长时间(但如果用户按住超过5秒,则在操纵完成之前将执行
勾选
事件)答:你完全正确。当用户点击图像5次时,计数器将为b 0,计数器将为b 0时,勾号事件将被执行。因此存在混乱。我想要的是,当用户仅在计时器启动的条件下按住图像5秒时的情况。此答案(更新了一点以避免混乱)建议另一种方法。
Tick
事件将在用户开始按住图像5秒后执行,方法是将
Interval
设置为5秒。如果用户稍后在5秒之前停止按住,则计时器将停止,这样
Tick
事件将不会执行。无需手动计算所用秒数。。。