(nevermind I am an idiot)ListBox: Add value to collection of type 'System.Windows.Controls.ItemCollection' threw an exception

Aug 5, 2010 at 3:14 PM
Edited Aug 5, 2010 at 3:22 PM

Disregard.

I didn't have the inner ItemControl info inside a DataTemplate.

 

I am getting the following error when after I drop an Item on the following control:
Error:

{"Add value to collection of type 'System.Windows.Controls.ItemCollection' threw an exception."}
{"Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."}

I have not tried to alter anything inside of Properties. I have added to properties in the Source not on the control itself (see DropCommand below).
I can Bind to Properties using the ItemsControl but as soon as I add a control (bound or unbound) inside the DataTemplate it gives the error.

XAML:

<ListBox x:Name="mSelectedQueriesListBox" VerticalAlignment="Stretch" Grid.Column="2" AllowDrop="True" ItemsSource="{Binding SelectedQuery.SelectedProperties}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Drop">
            <cmd:EventToCommand Command="{Binding AddSelectedPropertyCommand}" PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderBrush="#7998C6" Margin="3" Padding="3" BorderThickness="2" CornerRadius="5">
                <Expander Header="{Binding Name}">
                    <ItemsControl ItemsSource="{Binding Properties}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" />
                            <CheckBox IsChecked="{Binding Show}" />
                            <Button Content="..." />
                            <TextBlock Text="{Binding DisplayName}" />
                        </StackPanel>
                    </ItemsControl>
                </Expander>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

 

Drop Command ...

SelectedQuery.AddProperty((PropertyCollectionViewModel)e.Data.GetData(typeof(object)));