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

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


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:

{"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.


<ListBox x:Name="mSelectedQueriesListBox" VerticalAlignment="Stretch" Grid.Column="2" AllowDrop="True" ItemsSource="{Binding SelectedQuery.SelectedProperties}">
        <i:EventTrigger EventName="Drop">
            <cmd:EventToCommand Command="{Binding AddSelectedPropertyCommand}" PassEventArgsToCommand="True" />
            <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}" />


Drop Command ...