Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All ComboBoxes in a ListBox change when any 1 of them is changed

I have a ListBox on a form that is bound to an ObservableCollection of a custom type. Within each item there is a ComboBox bound to an enumeration type. When the window loads, all ComboBoxes are defaulted to a certain value. When I change the SelectedItem for any one (from the UI, not from code), all other ComboBoxes change to the same SelectedItem.

I'm not sure what I've done wrong, here is my current XAML that is handling this.

<Window.Resources>
    <ObjectDataProvider x:Key="SyncOperationValues"
                        MethodName="GetNames"
                        ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:SyncOperationEnum" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
...
    <DataTemplate x:Key="SyncListTemplate">
        <Grid Grid.Column="1" Grid.RowSpan="2" Margin="0,0,20,0" x:Name="olDetails"
            DataContext="{Binding Path=OlContact}">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            <RowDefinition />
            </Grid.RowDefinitions>
...
            <ComboBox x:Name="SyncOp" 
                Width="120" Height="19"
                Margin="4,0,10,0" 
                IsSynchronizedWithCurrentItem="True" 
                ItemsSource="{Binding Source={StaticResource SyncOperationValues}}"
                             SelectedItem="{Binding Operation}"
                             VerticalAlignment="Center" />

...

and the ListBox:

 <ListBox x:Name="SyncList"
     ScrollViewer.HorizontalScrollBarVisibility="Hidden"
     ItemContainerStyle="{StaticResource StretchedContainerStyle}"
     ItemTemplate="{StaticResource SyncListTemplate}">
 ListBox>

I have tried some different options, like binding to a CollectionView; however nothing seems to work. Can anyone point me to my mistake?

Thanks!

like image 707
palehorse Avatar asked Dec 30 '22 05:12

palehorse


1 Answers

I had a situation similar to this and setting the IsSynchronizedWithCurrentItem property on the ComboBox to "False" fixed it. The way I understand it, setting the value to "True" means the ComboBox value will be synchronized value of the current item for the ListBox. Basically, all the ComboBoxes are bound to that same value. It sounds like that is what you are experiencing. Try:

IsSynchronizedWithCurrentItem="False"
like image 180
John Myczek Avatar answered May 03 '23 08:05

John Myczek