Order in XAML is important when using data binding

Today I was bitten by something I hadn’t anticipated: order in XAML is important when using data binding. After I discovered this, I found this has stung several other people (see this stackoverflow post, or this blog post).

Basically it comes down to this:

<ComboBox ItemsSource="{Binding Employees}" SelectedItem="{Binding SelectedEmployee, Mode=TwoWay}"/>

will work, because the list of Employees is bound first, after which the SelectedEmployee can be bound succesfully, resulting in a selected Employee from the list of Employees.

<ComboBox SelectedItem="{Binding SelectedEmployee, Mode=TwoWay}" ItemsSource="{Binding Employees}"/>

will NOT work, because the SelectedEmployee is bound first, after which the list of Employees is bound, erasing the SelectedEmployee selection.

I would say this is a feature that could be marked as a bug.