I have seen multiple other posts about this (e.g. http://www.telerik.com/forums/backspace-clears-the-combobox-selecteditem) but I don't think any of them are asking the same question...
I have a RadComboBox which contains a collection of objects (i.e. it's not editable). I have set the SelectedValuePath to indicate which property contains the value that SelectedValue should represent. One of the items has a "null" as the value, so when the value that it is bound to is "null", this is the item which appears. I'm using MVVM to bind to a ViewModel, but I don't think that affects the issue.
When the backspace button is pressed, the ViewModel's property which is bound to SelectedValue is set to null (this doesn't happen if the "null" value object was the one that was selected at the time). But the issue is that the box contents are cleared. Since the SelectedValue is now null, I would expect the control to be showing the item whose SelectedValue is "null". Two good reasons why it ought to do that...
1) symmetry: that is what happens when the window first opens if the bound value is "null"
2) when the "null" value object was the one that was selected when backspace was pressed, the control didn't bother mentioning to the change to the bound ViewModel, so *it* believes that nothing has changed; but the UI now does not correspond with the SelectedValue.
Here is a really simplistic example:
Create a new WPF application.
Replace MainWindow.xaml with...
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication4"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MainWindowViewModel/>
</Window.DataContext>
<Grid>
<telerik:RadComboBox SelectedValuePath="Tag" SelectedValue="{Binding MySelectedValue}">
<telerik:RadComboBox.Items>
<telerik:RadComboBoxItem Content="Hello" Tag="Hello"/>
<telerik:RadComboBoxItem Content="This" Tag="{x:Null}"/>
<telerik:RadComboBoxItem Content="Is" Tag="Is"/>
<telerik:RadComboBoxItem Content="A" Tag="A"/>
<telerik:RadComboBoxItem Content="Test" Tag="Test"/>
</telerik:RadComboBox.Items>
</telerik:RadComboBox>
</Grid>
</Window>
--Ends--
Add "MainWindowViewModel.cs", contents follow...
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace WpfApplication4
{
public class MainWindowViewModel : INotifyPropertyChanged
{
private object _mySelectedValue;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public object MySelectedValue
{
get
{
return _mySelectedValue;
}
set
{
_mySelectedValue = value;
OnPropertyChanged();
}
}
}
}
--Ends--