WPF ComboBox数据绑定:初始化动态加载ItemsSource后首次赋值Text不显示问题解决
原来:
<ComboBox Text="{Binding Item}" ItemsSource="{Binding ItemLists}"></ComboBox>
private void Paras_Init() { ItemLists = new ObservableCollection<string>(); ItemLists.Add("11111"); ItemLists.Add("22222"); ItemLists.Add("33333"); ItemLists.Add("44444"); ItemLists.Add("55555"); Item = "44444"; }
效果:值已绑定,但不显示

修改方式1:将Text的绑定放在后面
<ComboBox ItemsSource="{Binding ItemLists}" Text="{Binding Item}" ></ComboBox>
效果:

修改方式2:将Text绑定改为SelectedItem绑定
<ComboBox SelectedItem="{Binding Item}" ItemsSource="{Binding ItemLists}"></ComboBox>
效果:


浙公网安备 33010602011771号