protected override void OnKeyDown(KeyEventArgs args)
{
base.OnKeyDown(args);
int index = unigrid.Children.IndexOf(cellHighlighted);
int y = index / xNum;
int x = index % xNum;
switch (args.Key)
{
case Key.Home:
y = 0;
x = 0;
break;
case Key.End:
y = yNum - 1;
x = xNum + 1;
break;
case Key.Down:
if ((y = (y + 1) % yNum) == 0)
x++;
break;
case Key.Up:
if ((y = (y + yNum - 1) % yNum) == yNum-1)
x--;
break;
case Key.Right:
if ((x = (x + 1) % xNum) == 0)
y++;
break;
case Key.Left:
if ((x = (x + xNum - 1) % xNum) == xNum-1)
y--;
break;
case Key.Enter:
case Key.Space:
if (cellSelected != null)
cellSelected.IsSelected = false;
cellSelected = cellHighlighted;
cellSelected.IsSelected = true;
clrSelected = (cellSelected.Brush as SolidColorBrush).Color;
OnSelectedColorChanged(EventArgs.Empty);
break;
default:
return;
}
if (x >= xNum || y >= yNum)
MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
else if (x < 0 || y < 0)
MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
else
{
cellHighlighted.IsHighlighted = false;
cellHighlighted = cells[y, x];
cellHighlighted.IsHighlighted = true;
}
args.Handled = true;
}