Currently, the drop down of RadComboBox contains only the RadComboBoxItems and the Clear Selection button. Add new content presenter that allows you to include extra visuals, like buttons or text.
The feature is similar to the AdditionalContent of RadTabControl.
The exception message is the following: System.ArgumentException: 'The value '102' is not a valid value for the enum 'FilterOperator'.'
To work this around, avoid using mixed typed values in the ItemsSource.
The items of the RadComboBox control flicker when scrolling and the Windows 11 theme is applied.
To work this around, a new Style with TargetType="RadComboBoxItem" could be created for the ItemContainerStyle property of RadComboBox. Then, set the BorderBrush and ThemeHelper.MouseOverBrush properties to "#F9F9F9".
xmlns:helpers="clr-namespace:Telerik.Windows.Controls.Theming.Helpers;assembly=Telerik.Windows.Controls"
<telerik:RadComboBox.ItemContainerStyle>
<Style TargetType="telerik:RadComboBoxItem">
<Setter Property="helpers:ThemeHelper.MouseOverBrush" Value="#F9F9F9" />
<Setter Property="BorderBrush" Value="#F9F9F9"/>
</Style>
</telerik:RadComboBox.ItemContainerStyle>
The selected items of the RadComboBox will not be displayed correctly if the ItemsSource is bound to a collection of enums that are converted via a custom EnumConverter.
Currently, you could work around this behavior by implementing a custom DataTemplate for the MultipleSelectionBoxTemplate property of RadComboBox:
<telerik:RadComboBox x:Name="comboBox"
AllowMultipleSelection="True">
<telerik:RadComboBox.MultipleSelectionBoxTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ElementName=comboBox, Path=SelectedItems}"
AlternationCount="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="commaTextBlock" Text=", "/>
<TextBlock Text="{Binding}" HorizontalAlignment="Left"/>
</StackPanel>
<DataTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Visibility" TargetName="commaTextBlock" Value="Collapsed" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</telerik:RadComboBox.MultipleSelectionBoxTemplate>
</telerik:RadComboBox>
Setting the Background property of RadComboBox no longer changes the background color of the control.
To work this around, you can add a global event handler for the Loaded event of RadComboBox and set the corresponding backgrounds in code.
static MainWindow()
{
EventManager.RegisterClassHandler(typeof(RadComboBox), RadComboBox.LoadedEvent, new RoutedEventHandler(OnComboBoxLoaded));
}
private static void OnComboBoxLoaded(object sender, RoutedEventArgs e)
{
var comboBox = (RadComboBox)sender;
if (!comboBox.IsEditable)
{
if (comboBox.IsEnabled)
{
var buttonChrome = comboBox.FindChildByType<ButtonChrome>();
buttonChrome.Background = Brushes.Purple;
}
else
{
comboBox.Background = Brushes.Purple;
}
}
}
NullReferenceException appears when the multiple selection is enabled, items are selected and the Text property of the RadComboBox control becomes null.
To resolve this, you can override the OnTextChanged method of RadComboBox and replace the null value with an empty string.
public class CustomRadComboBox : RadComboBox
{
protected override void OnTextChanged(string oldValue, string newValue)
{
if (string.IsNullOrEmpty(newValue))
{
newValue = string.Empty;
Dispatcher.BeginInvoke(new Action(() =>
{
SelectedItems.Clear();
}));
}
base.OnTextChanged(oldValue, newValue);
}
}
In this case, the control is bound to a collection of strings. The collection contains equal string values. ("h1","h2","h1"). When the first item is selected and afterward we select the last one, will not trigger the SelectionChanged event. This behavior could be improved.
Steps to Create Problem using EditableTextBoxTemplate_WPF sample project provided by Telerik:(modified project is zipped and attached just in case)
- Edit Example.xaml to add "AllowMultipleSelection="True":
<telerik:RadComboBox IsEditable="True" ItemsSource="{Binding Companies}" SelectAllTextEvent="None" FontFamily="Calibri" FontSize="14"
1) Run project
2) Click drop down button to see list in the drop down
3) Type "Global" (at this point it should autocomplete "Global Corporation")
4) Without clicking on anything or Press space bar to continue typing (type space character)
5) Typed text will disappear leaving only space character behind - At this point, nothing is selected.
This does NOT happen if typed text before space does NOT match with any item from the list.
This does NOT happen if AllowMultipleSelection set to false.
This does NOT happen if dropdown is NOT open while typing.
The "{" character cannot be entered in the RadComboBox when the keyboard is German (Swiss).
As a wokaround, you can inherit the RadComboBox and override the HandleKeyDown method:
public class CustomRadComboBox : RadComboBox
{
protected override bool HandleKeyDown(Key systemKey, int platformKeyCode)
{
if(systemKey == Key.Oem5)
{
return false;
}
return base.HandleKeyDown(systemKey, platformKeyCode);
}
}
According to the following article, when the UpdateSelectionOnLostFocus property is set to True and you enter a text that cannot update the selection, once the control loses the focus, the typed text should stay in the textbox.
https://docs.telerik.com/devtools/wpf/controls/radcombobox/howto/perform-selection-only-lost-focus
However, this doesn't happen if an item is already selected. In this case, the searched text is cleared. If you do not have a selection, then the text stays on lost focus.
To work this around, you can cache the value of the RadComboBox's Text property in the PreviewLostKeyboardFocus event handler and then restore it in the LostFocus event handler.
private string textCache;
private void RadComboBox_PreviewLostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
this.textCache = this.comboBox.Text;
}
private void RadComboBox_LostFocus(object sender, RoutedEventArgs e)
{
this.comboBox.Text = this.textCache;
}
When the theme variation is changed in the VisualStudio2013 theme, the mouse over color is not updated.
As a workaround, we can reset the Template of the RadComboBox.
var template = this.comboBox.Template;
this.comboBox.Template = null;
this.comboBox.Template = template;