Hi,
I have a XamComboEditor which is bound to an ItemsSource which has a list of custom Entity instances. Entity has an integer Id and string Code properties. I set the ValuePath="Id" and DisplayMemberPath="Code". And I also set the Value property of combo to a property named "SelectedValue" on window in order to explain my problem.
The thing when the SelectedValue is 0, so the Value of Combo, the display text on XamComboEditor shows "0" since there is no Entity with Id = 0 in ItemsSource. What I want the combo is to show NOT 0 but empty string when the value is not found in ItemsSource. There is an option for that in some components but couldn't find on XamComboEditor. I've also tried to use ValueToTextConverter and ValueToDisplayTextConverter to convert 0 to String.Empty but they didn't work either.
I've attached the sample project in order to show the problem.
Can somebody help me out?
Thanks in advance
Hello,
This looks like an issue in the XamComboEditor. This should be achievable with the ValueToDisplayTextConverter and I see it is being called when the editor loads, but the text is not being changed.
As a temporary solution, you could use the ValueChanged event of the XamComboEditor and check if the e.NewValue is 0 and change the Text property of the editor. Please note that this will probably throw some exceptions (silently) saying that a string cannot be converter to an int32 as the XamComboEditor is expecting an integer rather than a string.
private void XamComboEditor_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.NewValue is int && (int)e.NewValue == 0)
(sender as XamComboEditor).Text = "null text";
}
Another way would be to place the text in the adorner layer of the XamComboEditor when it's value is equal to 0.