I have a UserControl with a ICommand-derived object as a Resource as follows:
<commands:SetRegionContentCommand x:Key="SetContentComand"/>
I then try to bind the command to the DataTemplate tag within an ItemsControl like so:
<ItemsControl ItemsSource="{Binding Path=Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Grid.Column="1" Command="{Binding Source={StaticResource SetContentComand}}" CommandParameter="{Binding}">
<Image Source="plus.jpeg" Width="16" Height="16"/>
</Button>
</...
However, when this happens I get "Element is already the child of another element" error messages in the browser. How can I prevent these errors from occurring?
I can see that the Command is being attached to the UserControl several times, but I want this to happen. How else does one bind commands to repeating databound controls?