I have a UserControl "SubjectListView". The binding is set to "AllSubjects" which is an ObservableCollection inside the SubjectListViewModel. It is used to retrieve the name and execute the command. The name is retrieved, however the command which is also in the SubjectListViewModel is not executed on the button but works on the button which is not dynamically created outside the scope.
Is there a solution?
<StackPanel> <ItemsControl ItemsSource="{Binding AllSubjects}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Button Width="100" Content="{Binding Name}" <!-- Is working--> Command="{Binding InvasionCommand}" <!--Is NOT working--> /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <Button Content="Check for Invasion" Width="120" Command="{Binding InvasionCommand}" <!-- Is working-->/> </StackPanel>
StackPanelanx:Name. on your Command Binding, useElementNameto direct to the namedStackPanel, then doPath=DataContext.InvasionCommand