
I tried focusing the control and as soon as I press space bar or arrow to navigate the list box, the popup closes. Here's the code for reference:
<UserControl x:Class="Test.Popup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
mc:Ignorable="d"
d:DesignHeight="40"
d:DesignWidth="200"
x:Name="root">
<Grid>
<ribbon:PopupButton x:Name="_popupButton">
<ribbon:PopupButton.PopupContent>
<ListBox x:Name="_popup" FocusManager.IsFocusScope="True" SelectedIndex="{Binding Path=Type, ElementName=root, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}" BorderBrush="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" MinHeight="22"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBoxItem Content="Choice 1"/>
<ListBoxItem Content="Choice 2"/>
<ListBoxItem Content="Choice 3"/>
</ListBox>
</ribbon:PopupButton.PopupContent>
</ribbon:PopupButton>
</Grid>
</UserControl>
protected override void OnKeyDown(KeyEventArgs e)
{
if (e == null)
return;
if (e.Handled)
return;
Key key = e.Key;
if (key == Key.System)
key = e.SystemKey;
switch (key)
{
case Key.Escape:
_popupButton.IsPopupOpen = false;
e.Handled = true;
return;
// Drop down
case Key.F4:
Popup();
e.Handled = true;
return;
case Key.Up:
case Key.Down:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
{
Popup();
e.Handled = true;
}
return;
}
}
private void Popup()
{
_popupButton.IsPopupOpen = true;
_popup.Focus();
//System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
//{
// _popup.Focus();
// Keyboard.Focus(_popup);
// //var item = _popup.SelectedItem as IInputElement;
// //if (item == null)
// // item = _popup.Items[0] as IInputElement;
// //if (item != null)
// //{
// // item.Focus();
// // Keyboard.Focus(item);
// //}
//}), System.Windows.Threading.DispatcherPriority.Normal);
}