Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. Error while parsing XAML

StackOverflow https://stackoverflow.com/questions/15625974

Question

I get a runtime error that crashes when it tries to parse my XAML.

<TreeViewItem Header="{Binding Header}" ItemsSource="{Binding DataGroups}">
    <ListView ItemsSource="{Binding DataGroups}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Group Name" DisplayMemberBinding="{Binding Path=Name}" />
                <GridViewColumn Header="Group Type" DisplayMemberBinding="{Binding Path=Type}" />
            </GridView>
        </ListView.View>
    </ListView>
</TreeViewItem>
Was it helpful?

Solution

After searching through all the questions related to this, I couldn't find the answer. Most involved people changing the Items property on the TreeViewItem, which will throw this error.

In my case, I didn't change anything.

However, if you notice.

<TreeViewItem Header="{Binding Header}" ItemsSource="{Binding DataGroups}">
    <ListView ItemsSource="{Binding DataGroups}">

I have bound to the same collection twice.

So, double check you haven't bound to the same collection twice if you get this error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top