Posted 12 February 2018, 2:09 am EST
Xamarin.Forms
C1 version: v2.5.20173.241
Affected platforms: UWP, iOS
Unaffected platforms: Android
I have a simple, editable C1ComboBox.
<input:C1ComboBox
x:Name="TheComboBox"
IsEditable="True"
DropDownBehavior="ButtonTap" />
In some scenarios, the ItemsSource may actually get set to nothing, either null or an empty collection. However, we still want users to be able to type in them. The issue comes when we try to programatically clear these C1ComboBoxes. The following works on Android, but not UWP or iOS.
private void Button_OnClicked(object sender, EventArgs e)
{
TheComboBox.Text = "";
}
On UWP, you can see the text property is properly set as the entered in text, and setting it to an empty string is reflected on the property. But, it doesn’t seem to affect what is visually displayed in the C1ComboBox. If fact, this is true if you set Text to anything, including null. It still displays the entered in text. However, as long as the ItemsSource is null, I did find that setting the SelectedIndex to anything > -1 (even though there are no items) does clear the text. I wouldn’t have been surprised if that caused an error.
However, the SelectedIndex trick does not work on iOS. iOS seems to have a few issues here. The first time my button click handler fires, no matter what is entered into the C1ComboBox, the Text property is an empty string. If I set the Text property to some string other than an empty string it does change, both on the property an visually. But, if I type something else in and click the button, the Text property shows what I had set it to programatically before, not what I typed in. The string I typed in stays displayed. The only thing that seems to work is if I set the Text property to null. For some reason, when I set it to null, the Text property is always an empty string on subsequent button clicks and null clears it out.
So my UWP workaround is to set the SelectedIndex to something > -1 and my iOS workaround is to set the Text to null (which does also work on Android). I would really just expect them to work like Android though.