New to Telerik UI for WinUI? Download free 30-day trial

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

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

<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

In this article
Not finding the help you need?