views:

281

answers:

3

Hi, I want to disable the navigation on press of UP and Down arrow keys in Silverlight.

I tried with a case statement:

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;
         }

    }

This is not Workin :( . Help

A: 

You want e.Handled = true;. If you say false you are saying "I didn't handle this so go ahead and let the default handler do its thing."

Jonathan Allen
I tried Setting e.Handled = true. Even now the up and down keys works.
Subhen
A: 

Try the KeyUp event instead and say e.Handled=true...

Veer
You're already using KeyUp event?
Veer