When you are inside the DataTemplate ListView , your data context is the current ListView ItemsSource . Since in your AllAcounts "every single element is not called" NavigateToAccountsCommand ", the binding does not work.
To fix this, you will need to reference something outside the DataTemplate ; the following should work. It changes the binding to the link to the root grid of the DataContext , which should have the NavigateToAccountsCommand property. To reference the grid, you need to add the Name attribute, and then use the ElementName binding.
<Grid Name="Root"> <!--**This one is working**--> <Button Command="{Binding NavigateToAccountsCommand}" > <!--**This one is not working**--> <ListView ItemsSource="{Binding AllAccounts}" > <ListView.ItemTemplate> <DataTemplate> <StackPanel HorizontalAlignment="Stretch"> <TextBlock Text="{Binding AccountName}"/> <Button Command"{Binding ElementName=Root, Path=DataContext.NavigateToAccountsCommand}"> </Button> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid>
loopedcode
source share