To illustrate both success and failures, I'm going to use the following backend. In each case, I have an array of things, and a Property that is set to the array.First().
public class MainPage
{
public MainPage()
{
this.InitializeComponent();
FirstString = Strings.First();
FirstItem = Items.First();
}
public string FirstString { get; set; }
public Item FirstItem { get; set; }
public string[] Strings => new[] {"1", "2", "3", "4"};
public Item[] Items => new[]
{
new Item {Index = 1},
new Item {Index = 2},
new Item {Index = 3},
new Item {Index = 4}
};
}
public class Item
{
public int Index { get; set; }
}
So here is a binding results in the item in the SelectedItem
being selected
<ComboBox ItemsSource="{x:Bind Strings}"
SelectedItem="{x:Bind FirstString}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="system:String">
<TextBlock Text="{x:Bind}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
And here is the identical code for the alternate items that fails to select
<ComboBox ItemsSource="{x:Bind Items}"
SelectedItem="{x:Bind FirstItem}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:Item">
<TextBlock Text="{x:Bind Index}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Additionally as soon as I turn on Mode=TwoWay
this clears my value in the VM during the initial bind.
So my question is, Why? What is different to cause this?