У меня есть тег кнопки внутри моего шаблона данных.Я хочу вызвать команду, как только я нажму на кнопку.Если кнопка находится за пределами шаблона данных, моя кнопка может работать.Я пробовал несколько решений, таких как:
<Button x:Name="btnUpdate" Content="Update" VerticalAlignment="Center" HorizontalAlignment="Right" Click="btnUpdate_Click"
Command="{Binding Path=DataContext.updateProductionLineConfigCommand,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"/>
Это моя ViewModel:
public UpdateProductionLineConfigCommand updateProductionLineConfigCommand { get; set; }
public ProductionLineConfigViewModel()
{
ProductionLineConfig = new ProductionLineConfig();
newProductionLineConfigCommand = new NewProductionLineConfigCommand(this);
updateProductionLineConfigCommand = new UpdateProductionLineConfigCommand(this);
}
Это мой командный класс:
public ProductionLineConfigViewModel VM { get; set; }
public event EventHandler CanExecuteChanged;
public UpdateProductionLineConfigCommand(ProductionLineConfigViewModel vm)
{
VM = vm;
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
VM.updateProductionLineConfig();
}
Может кто-нибудь, пожалуйста, помогите мнена этом.Почему я не могу связать свои команды с моей кнопкой?