# ToggleColumnVisibility Command

The `ToggleColumnVisibility` command handles the process of switching the `IsVisible` property of a column. The default implementation will toggle the visibility. The command is useful when customers need a notification when the end user excludes or includes a column.

## Execution Parameter

The execution parameter is of type `ToggleColumnVisibilityContext` and exposes the following properties:

* `IsColumnVisible` (bool)—Gets or sets a value indicating whether the column is visible.
* `Column`—Gets the `DataGridColumn` instance that is being shown or hidden.

## Custom ToggleColumnVisibility Command

The following examples show how to create a class that inherits from the `DataGridCommand` and add it to the `Commands` collection.

#### **Create a Custom ToggleColumnVisibility Command**

```C#
public class CustomToggleColumnVisibilityCommand : DataGridCommand
{
	public CustomToggleColumnVisibilityCommand()
	{
		this.Id = CommandId.ToggleColumnVisibility;
	}

	public override bool CanExecute(object parameter)
	{
		var context = parameter as ToggleColumnVisibilityContext;
		// put your custom logic here
		return true;
	}

	public override void Execute(object parameter)
	{
		var context = parameter as ToggleColumnVisibilityContext;
		// put your custom logic here

		this.Owner.CommandService.ExecuteDefaultCommand(CommandId.ToggleColumnVisibility, context);
	}
}
```

#### **Add the Custom Command to the Commands Collection**

```XAML
<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid">
	<grid:RadDataGrid Width="600" Height="460" x:Name="grid" Hold>
		<grid:RadDataGrid.Commands>
			<local:CustomToggleColumnVisibilityCommand />
		</grid:RadDataGrid.Commands>
	</grid:RadDataGrid>
</Grid>
```

## See Also

* [CellTap](https://www.telerik.com/winui/documentation/controls/raddatagrid/commands/datagrid-celltapcommand)
* [CellDoubleTap](https://www.telerik.com/winui/documentation/controls/raddatagrid/commands/datagrid-celldoubletappedcommand)
* [ColumnHeaderTap](https://www.telerik.com/winui/documentation/controls/raddatagrid/commands/datagrid-columnheadertapcommand)
