In DataGrid
I have a column defined like this.
<DataGridTemplateColumn Width="Auto">
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
APPROACH
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
First approach
<Button Template="{StaticResource CloseTabButton}" Command="{Binding DataContext.DeleteRangeCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}"/>
Second approach
<Button Template="{StaticResource CloseTabButton}" Command="{Binding ElementName=CurrentWindow, Path=DataContext.DeleteRangeCommand}" CommandParameter="{Binding}"/>
In ViewModel:
public RelayCommand<Range> DeleteRangeCommand
{
get { return _deleteRangeCommand ?? (_deleteRangeCommand = new RelayCommand<Range>((x) => ReportGroup.Ranges.Remove(x))); }
}
Both approaches should be identical. Problem is that, on some computers - I guess these without Visual Studio Installed, second approach doesn't work. Nothing is firing, I tried to attach with Remote Debugger and Command is not fired. Why is this possible?
OfCourse CurrentWindow
is x:Name
of Window with DataContext
set to ViewModel