Friday, July 19, 2013

Binding a ComboBox in a DataTemplate with XAML

I've been struggling to figure out how to bind a ComboBox inside of a ListView's DataTemplate. The problem I experienced was that when I changed the value of one ComboBox, all other ComboBoxes in the list got changed to the same value. Turns out the answer is to simply use the IsSynchronizedWithCurrentItem property. Hope I remember this one the next time around.
ItemsSource="{Binding Source={StaticResource deliveryTimesViewSource}, Mode=OneWay}"
SelectedItem="{Binding DeliveryHour, Mode=TwoWay, Converter={StaticResource deliveryHourToObjectConverter}, ConverterParameter={StaticResource deliveryTimesViewSource}}"