RadListBox allows you to navigate between the items using the arrow keys on the keyboard. To enable this, you will need to select any item in order to focus the control. Using touch input to select an item, instead of the mouse, is breaking the arrow keys navigation. Pressing up and down no longer navigates to the previous and next item.
To work this around, subscribe the RadListBox control to the TouchManager.Tap event and focus the tapped RadListBoxItem in the event handler.
public MainWindow()
{
InitializeComponent();
TouchManager.AddTapEventHandler(this.listBox, this.OnTap, true);
}
private void OnTap(object sender, TapEventArgs e)
{
var tapElement = (FrameworkElement)e.OriginalSource;
var item = tapElement.ParentOfType<RadListBoxItem>();
if (item != null)
{
item.Focus();
}
}
In this particular scenario, the RadListBox is placed inside DataTemplate and its ItemsSource property is bound to CollectionViewSource.View. Now when we try to bind the SelectedItem property, the binding fails. The reason behind this is that when the RadListBox is loading, the CurrentItem of the CollectionViewSource is set to the SelectedItem property after the binding kicks in. Which will break the binding. To workaround this we can set the CurrentItem to Null.
MyCollectionViewSource.View.MoveCurrentToPosition(-1);
The border of the RadListBox is missing in the Office2019 theme if System.Windows.xaml resource dictionary is not merged.
If you set the SelectedIndex after an item is added in the Items or ItemsSource of RadListBox, the selection doesn't work.
To work this around, use the SelectedItem property instead of SelectedIndex.
public
class
CustomListBox : RadListBox
{
protected
override
bool
HandleKeyboardInput(Key key)
{
if
(key == Key.Space)
{
return
false
;
}
return
base
.HandleKeyboardInput(key);
}
}
SelectionChanging event could be added for preventing selection in code, just like SelectionChanging event in RadGridView and PreviewSelectionChanged in RadTreeView