2010-03-26 72 views
0

我想在Silverlight中按下向上和向下箭頭鍵禁用導航。如何禁用silverlight列表框的向上和向下箭頭鍵?

我試圖用一個case語句:

void lisBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) 
    { 
     int numberofItems = lisBox.Items.Count-1; 
     Keys key = (Keys)e.Key; 
     switch (key) 
     { 
      case Keys.LEFT: 
       if (lisBox.SelectedIndex > 0) 
       { 
        lisBox.SelectedIndex = lisBox.SelectedIndex - 1; 
       } 
       break; 
      case Keys.RIGHT: 

       if (lisBox.SelectedIndex < numberofItems) 
       { 
        lisBox.SelectedIndex = lisBox.SelectedIndex + 1; 
       } 
       break; 
      case Keys.UP: 
       e.Handled = true; 
       lisBox.SelectedIndex = lisBox.SelectedIndex - 4; 
       break; 
      case Keys.DOWN: 
        e.Handled = true; 
       lisBox.SelectedIndex = lisBox.SelectedIndex - 4; 
       break; 
     } 

    } 

這不是日夜不停:(幫助

回答

0

你想e.Handled = true;如果你說false你說「我沒有處理這個這麼下去。繼續並讓默認的處理程序做它的事。」

+0

我試過設置e.Handled = true。即使現在上下鍵都可以工作。 – Simsons 2010-03-26 09:38:36

0

嘗試KeyUp事件,而不是說e.Handled =真...

+0

你已經在使用KeyUp事件了嗎? – Amsakanna 2010-03-26 09:59:57

相關問題