RelativeSource. Изменение DataContext в DataTemplate
View:
<StackPanel Grid.Column="0" Grid.Row="1" VerticalAlignment="Top" >
<ListBox ItemsSource = "{Binding Kernels}" HorizontalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="5">
<Button Command="{Binding RemoveKernel, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding Kernels}" Content="Delete" Margin="5" Width="40" Height="18" VerticalAlignment="Center" />
<TextBlock Text="{Binding Title}" Margin="5" FontSize="16" VerticalAlignment="Center" />
<CheckBox IsChecked="{Binding IsVisualizationKernel}" Margin="5" FontSize="16" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
Kernels это ObservableCollection. Во нажатию кнопки <Button Command="{Binding AddKernel}"/> Добавляются новые элементы в список. Если я правильно понял, DataTemplate меняет DataContext, которым является моя ViewModel. И поэтому привязки(RemoveKernel, Title, IsVisualizationKernel) не срабатывают(хотя вне DataTemplate они срабатывали). Я пытался сделать(всяка-разна) RelativeSource для RemoveKernel, но безуспешно, привязка всё равно не работает.