我正在使用ComboBox控件,无法从我的viewmodel上的属性中设置SelectedItem.这是控件定义:
<ComboBox x:Name="jobEmployee" Grid.Column="1" Grid.Row="2"
Margin="4" HorizontalAlignment="Left" Width="150"
SelectedItem="{Binding Path=EditingJob.Employee, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
ItemsSource="{Binding Path=Employees, Mode=OneWay}"
DisplayMemberPath="FullName"/>
Run Code Online (Sandbox Code Playgroud)
我有另一个Combobox控件,工作得很好.设置SelectedItem的设备与不设置SelectedItem的设备之间的差异是属性定义的顺序.这是工作控件定义:
<ComboBox x:Name="jobEmployee" Grid.Column="1" Grid.Row="2"
Margin="4" HorizontalAlignment="Left" Width="150"
ItemsSource="{Binding Path=Employees, Mode=OneWay}"
SelectedItem="{Binding Path=EditingJob.Employee, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
DisplayMemberPath="FullName"/>
Run Code Online (Sandbox Code Playgroud)
2之间的区别在于ItemsSource是在工作的SelectedItem之前定义的,这使我相信至少在这种情况下,属性定义顺序很重要.我错过了什么或让别人发现这是真的吗?有没有记录在任何地方?