Rafael
Rafael

Reputation: 108

Datatemplate for combobox not switching selected value when binded with Entity Framework

At runtime all the items are selected with the same item.

How can I make it so that it will all be binded to their respective Datacontext?

<ComboBox ItemsSource="{Source={StaticResource CalculationTypesLookUp}}" Grid.Row="1" Grid.Column="1" 
                      DisplayMemberPath="CalculationTypeDescription"
                      SelectedValuePath="Id"
                      SelectedValue="{Binding CalculationTypeId, Mode=TwoWay}"/>

Upvotes: 2

Views: 31

Answers (1)

RSquared
RSquared

Reputation: 66

If you add IsSynchronizedWithCurrentItem="False" it will fix your issue. By default it will be set to true IsSynchronizedWithCurrentItem="True" making all the datatemplate instances the same.

<ComboBox ItemsSource="{Binding Source={StaticResource CalculationTypesLookUp}}" Grid.Row="1" Grid.Column="1" 
                          DisplayMemberPath="CalculationTypeDescription"
                          SelectedValuePath="Id"
                          SelectedValue="{Binding CalculationTypeId, Mode=TwoWay}"
                          IsSynchronizedWithCurrentItem="False"/>

Upvotes: 3

Related Questions