为了说明成功和失败,我将使用以下后端。在每种情况下,我都有一些东西,并且一个属性设置为array.First()。UWP Combobox SelectedItem忽略其绑定值
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; }
}
因此,这里是在SelectedItem
项目进行了结合结果被选择
<ComboBox ItemsSource="{x:Bind Strings}"
SelectedItem="{x:Bind FirstString}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="system:String">
<TextBlock Text="{x:Bind}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
这里是对于未能选择
<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>
另外备用项相同的代码只要我打开Mode=TwoWay
,就会在初始绑定期间清除VM中的值。
所以我的问题是,为什么?导致这种情况有什么不同?
什么是您的输出窗口说什么? –
你在这里得到了非常有趣的问题。我会在未来的采访中使用它:) – AlexDrenea