2017-01-23 52 views
0

我试图检查图像是否被窃听或没有条件在UWP ,但不知道如何实现。 任何帮助,如果以下(pause.Tapped)是给错误 XAML来appreciated.Given试图检查图像是否被窃听如果条件在uwp

<Image x:Name="Pause" Source="ABCD/Pause.png" 
       RelativePanel.AlignBottomWithPanel="True" 
        RelativePanel.RightOf="Music" 
        Margin="17,0,0,0" Tapped="PauseTap" 
       Width="40" Height="40"/> 

C#代码

public ABCD() 
     { 
      this.InitializeComponent(); 
      LoopStart(); 
     } 

     public async void LoopStart() 
     {   
      if(Pause.Tapped) 
} 
+1

什么是你的目标实现,除了检测的其他方法攻?我问,因为我认为你想要的东西,并试图解决这个问题。你知道消息处理程序吗?和线程? – Stefan

+0

也许你应该把'Image'改成'Button'就好像暂停并处理'Click'事件? –

回答

0

你行,因为你治疗if(Pause.Tapped)将无法​​正常工作像属性一样的事件。相反,您可以使用事件处理程序设置标志来打破循环。
事情是这样的:

private bool _isPaused = false; 

ctor() 
{ 
    InitializeComponent(); 
    DoLooping(); 
} 

private void DoLooping() 
{ 
    // This will keep looping forever 
    while (true) 
    { 
     if (!_isPaused) 
     { 
      // do things here if not paused... 
     } 
    } 
} 

void PauseTap(object sender, EventArgs args) 
{  
    _isPaused = !_isPaused; // This will allow the pause button to act as a toggle 
} 
+0

我用你的代码示例,但点击暂停图像它不会执行,我想执行点击暂停 – anuj