This question is locked. New answers and comments are not allowed.
Hello,
I want to add a custom command column in my grid. It looks great so far but I am having trouble applying a row-specific parameter to the button. Can anyone assist me on this?
My C# ItemSource looks like:
public class AttendeeLookupViewModel
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
My grid column XAML looks like:
<grid:DataGridTemplateColumn CanUserEdit="False">
<grid:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<Button Content="VIEW">
<Button.Command>
<models:CustomGridCommand />
</Button.Command>
</Button>
</DataTemplate>
</grid:DataGridTemplateColumn.CellContentTemplate>
</grid:DataGridTemplateColumn>
My CustomGridCommand looks like:
public class CustomGridCommand : DataGridCommand
{
public CustomGridCommand()
{
this.Id = CommandId.CellTap;
}
public override bool CanExecute(object parameter)
{
DataGridCellInfo context = parameter as DataGridCellInfo;
// put your custom logic here
return true;
}
public override void Execute(object parameter)
{
DataGridCellInfo context = parameter as DataGridCellInfo;
// put your custom logic here
}
}
Any help is much appreciated!
I want to add a custom command column in my grid. It looks great so far but I am having trouble applying a row-specific parameter to the button. Can anyone assist me on this?
My C# ItemSource looks like:
public class AttendeeLookupViewModel
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
My grid column XAML looks like:
<grid:DataGridTemplateColumn CanUserEdit="False">
<grid:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<Button Content="VIEW">
<Button.Command>
<models:CustomGridCommand />
</Button.Command>
</Button>
</DataTemplate>
</grid:DataGridTemplateColumn.CellContentTemplate>
</grid:DataGridTemplateColumn>
My CustomGridCommand looks like:
public class CustomGridCommand : DataGridCommand
{
public CustomGridCommand()
{
this.Id = CommandId.CellTap;
}
public override bool CanExecute(object parameter)
{
DataGridCellInfo context = parameter as DataGridCellInfo;
// put your custom logic here
return true;
}
public override void Execute(object parameter)
{
DataGridCellInfo context = parameter as DataGridCellInfo;
// put your custom logic here
}
}
Any help is much appreciated!