2017-01-23 27 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