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);
}
}
The issue can be reproduced in a scenario in which there are a RadListBox and a RadGridView defined and their SelectedItem properties are bound to the same property in the view model. The source collection of RadListBox contains some objects present in the one bound to RadGridView's ItemsSource. If the user selects an item in RadGridView that is also present in the items of RadListBox, the selection is performed in both controls as expected. However, when already having a selected item in both controls, if the user selects an item in RadGridView that is not present in the items of RadListBox, the selection in RadListBox is not cleared. Thus, in order to selected the previously selected item, it needs to be deselected and selected again. UPDATE: After the researching the issue, it seems that the logic for handling the case when a SelectedItem that is not present in the source collection is being set is slightly different for Silverlight and WPF. For the WPF version of the control a DependencyProperty.UnsetValue is used, whereas a null value is set for the Silverlight RadListBox. Thus, in Silverlight the selection is cleared and in WPF it is not. I am afraid, that we cannot commit ourselves to modifying this by-design implementation, as this will result in a braking change. With this in mind, I will update the status of the logged bug to Declined. What we can suggest as a workaround, would be to define a second calculated property in the view model and bind the SelectedItem of RadListBox to it. The logic in the property setter would be to set a null value if the SelectedItem is not present in the source collection of RadListBox.