Hi,
i have a RadComboBox where the ItemsSource is bound to a list of strings, the Text to a String and where IsEditable is true.
When setting the Text (in viewmodel) to a value, which is not included in the list of strings, it shows the "suggested" text (like when i enter it manually in the box), not the text which was set.This occurs when the viewmodel value is set delayed (not in ctor).
Here is a small sample code.
MainWindow.xaml
<
Window
x:Class
=
"TelerikCombobox.MainWindow"
xmlns:local
=
"clr-namespace:TelerikCombobox"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
Title
=
"MainWindow"
Height
=
"450"
Width
=
"800"
>
<
Grid
>
<
StackPanel
Margin
=
"3"
>
<
telerik:RadComboBox
Text
=
"{Binding SelectedValue, Mode=TwoWay}"
ItemsSource
=
"{Binding SuggestedValues}"
IsEditable
=
"True"
/>
<
TextBlock
Text
=
"{Binding SelectedValue, Mode=OneWay}"
/>
</
StackPanel
>
</
Grid
>
</
Window
>
MainWindow.cs
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
this
.DataContext =
new
ViewModel()
{
SuggestedValues =
new
String[] {
"100"
,
"200"
,
"300"
},
};
SetValueDelayed();
}
private
async
void
SetValueDelayed()
{
await Task.Delay(2000);
if
(
this
.DataContext
is
ViewModel viewModel)
viewModel.SelectedValue =
"3"
;
}
}
ViewModel.cs
public
class
ViewModel : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
String m_SelectedValue;
public
String SelectedValue
{
get
{
return
m_SelectedValue;
}
set
{
m_SelectedValue = value;
PropertyChanged?.Invoke(
this
,
new
PropertyChangedEventArgs(nameof(SelectedValue)));
}
}
private
IEnumerable<String> m_SuggestedValues;
public
IEnumerable<String> SuggestedValues
{
get
{
return
m_SuggestedValues;
}
set
{
m_SuggestedValues = value;
PropertyChanged?.Invoke(
this
,
new
PropertyChangedEventArgs(nameof(SuggestedValues)));
}
}
}
After the value "3" is set, the combobox shows 300.
Thanks