<sync:SfDataGrid x:Name="syncgrid"
AllowFiltering="True"
AutoGenerateColumns="False"
ColumnSizer="Star"
ItemsSource="{Binding OrdersListDetails}"
NavigationMode="Cell">
<sync:SfDataGrid.Columns>
<syncfusion:GridTextColumn HeaderText="Order ID" MappingName="OrderID" TextAlignment="Left" />
<syncfusion:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID" />
<syncfusion:GridTextColumn HeaderText="Employee ID" MappingName="EmployeeID" TextAlignment="Right" />
<syncfusion:GridTextColumn HeaderText="Ship City" MappingName="ShipCity" />
<syncfusion:GridTextColumn HeaderText="Ship Country" MappingName="ShipCountry" />
<syncfusion:GridTextColumn DisplayBinding="{Binding Path=Freight, StringFormat='{}{0:c}'}" TextAlignment="Right" />
<syncfusion:GridTemplateColumn Width="50" MappingName="" AllowFiltering="False" AllowSorting="False">
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="30" Height="30" Command="{Binding ElementName=syncgrid, Path=DataContext.EditCommand}" CommandParameter="{Binding}">
Edit
</Button>
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
</syncfusion:GridTemplateColumn>
</sync:SfDataGrid.Columns>
</sync:SfDataGrid>
Added TemplateColumn with button and changed NavigationMode to Cell.
namespace DataBindingDemo
{
public class Command<T> : ICommand
{
public event EventHandler CanExecuteChanged;
public Action<T> Action;
public bool CanExecute(object parameter)
{
return true
}
public void Execute(object parameter)
{
Action.Invoke((T)parameter);
}
}
public class OrderInfoViewModel : NotificationObject
{
public ICommand EditCommand
{
get
{
return new Command<Orders>()
{
Action = (order) => { /*DO things with order*/ }
};
}
}
public OrderInfoViewModel()
{
OrdersListDetails = new OrderInfoRepository().PopulateOrders(200);
}
...
Added command class and EditCommand to OrderInfoViewModel class.
Everything else is unchanged.Hope it's clear enouph. Whenever the button "Edit" is pressend the Exception is thrown. Can someone explain what I'm doing wrong? As I said changing the NavigationMode to Row make the code run without problems. Am I missing something?
Cheers Antoine