2012-08-15 58 views
1

在Windows Phone 7應用程序中,是否可以在代碼中捕獲硬件攝像頭按鈕按下的事件? 現在,當我按下相機按鈕時,什麼也沒有發生,我無法弄清楚如何連接到事件。Wp7相機按鈕事件

+1

同樣的問題在這? http://stackoverflow.com/questions/8442571/camerabuttons-events-just-not-firing-in-wp7-1-app – Gambit 2012-08-15 17:29:03

回答

1

是的,你可以。檢查這個link。這是事件的一個例子:

// The event is fired when the shutter button receives a half press. 
CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress; 

// The event is fired when the shutter button receives a full press. 
CameraButtons.ShutterKeyPressed += OnButtonFullPress; 

// The event is fired when the shutter button is released. 
CameraButtons.ShutterKeyReleased += OnButtonRelease; 

// Provide auto-focus with a half button press using the hardware shutter button. 
private void OnButtonHalfPress(object sender, EventArgs e) 
{ 
     if (cam != null) 
     { 
      // Focus when a capture is not in progress. 
      try 
      { 
       this.Dispatcher.BeginInvoke(delegate() 
       { 
        txtDebug.Text = "Half Button Press: Auto Focus"; 
       }); 

       cam.Focus(); 
      } 
      catch (Exception focusError) 
      { 
       // Cannot focus when a capture is in progress. 
       this.Dispatcher.BeginInvoke(delegate() 
       { 
        txtDebug.Text = focusError.Message; 
       }); 
      } 
     } 
    }