powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / WPF ListBox
2 сообщений из 2, страница 1 из 1
WPF ListBox
    #35172212
prBoris
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Я уже замучился подскажите как правильно переключать фокус ?
У меня есть три лисбокса. Мне нужно по нажатию кнопки "Key.A" перейти в листбокс который находится левее. По нажатию "Key.D" который правее. По нажатию "Key.S" спускатся по списку листбокса в низ. По нажатию "Key.W" подниматься в по списку вверх. Я делаю так
MenuPlayer - это List<ListBox> MenuPlayer = new List<ListBox>();

private void Ganr_GotFocus(object sender, RoutedEventArgs e)
{
focusIndex = 0;
}

private void Ispolnitel_GotFocus(object sender, RoutedEventArgs e)
{
focusIndex = 1;
}

private void listPlay_GotFocus(object sender, RoutedEventArgs e)
{
focusIndex = 2;
}

if (e.Key == leftkey)
{
if (focusIndex > 0)
{
ItemsIndexSelected[focusIndex] = MenuPlayer[focusIndex].SelectedIndex;
MenuPlayer[focusIndex].SelectedIndex = -1;
MenuPlayer[focusIndex].ScrollIntoView(MenuPlayer[focusIndex].Items[0]);
MyTextBlock[focusIndex].Foreground = Brushes.Black;
focusIndex--;
MenuPlayer[focusIndex].SelectedIndex = ItemsIndexSelected[focusIndex];
MyTextBlock[focusIndex].Foreground = Brushes.Red;

}
}
else
{
if (e.Key == rightkey)
{
if (focusIndex < 2)
{
ItemsIndexSelected[focusIndex] = MenuPlayer[focusIndex].SelectedIndex;
MyTextBlock[focusIndex].Foreground = Brushes.Black;
focusIndex++;
if (MenuPlayer[focusIndex].Items.Count > 0)
{
MenuPlayer[focusIndex].Focus();
MenuPlayer[focusIndex].SelectedIndex = 0;
MenuPlayer[focusIndex].ScrollIntoView(MenuPlayer[focusIndex].Items[MenuPlayer[focusIndex].SelectedIndex]);
}
else
{
focusIndex--;
}
MyTextBlock[focusIndex].Foreground = Brushes.Red;
}
}
if (e.Key == upkey)
{
if (MenuPlayer[focusIndex].SelectedIndex > 0)
MenuPlayer[focusIndex].SelectedIndex--;
}

if (e.Key == downkey)
{
if (MenuPlayer[focusIndex].SelectedIndex < MenuPlayer[focusIndex].Items.Count - 1)
MenuPlayer[focusIndex].SelectedIndex++;

}

MenuPlayer[focusIndex].Focus();
MenuPlayer[focusIndex].SelectedValue = MenuPlayer[focusIndex].Items[MenuPlayer[focusIndex].SelectedIndex];
MenuPlayer[focusIndex].ScrollIntoView(MenuPlayer[focusIndex].Items[MenuPlayer[focusIndex].SelectedIndex]);
MenuPlayer[focusIndex].InvalidateVisual();

}

работает но очень глючит !!!
...
Рейтинг: 0 / 0
WPF ListBox
    #35172274
prBoris
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Как правильно сымитировать нажатия кнопки
if (e.Key == upkey)
{
Window1_KeyDown(this,new KeyEventArgs(e.KeyboardDevice,e.KeyboardDevice.ActiveSource,0,Key.Up));
}

что то не срабатывает !
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / WPF ListBox
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]