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

ToggleColumnVisibility Command

Handles the process of switching the IsVisible property of a column. Default implementation will simply toggle the visibility. This command is useful when customers need 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

Examples 1 and 2 show how to create a class that inherits from DataGridCommand and add it to the Commands collection.

Example 1: Creating 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); 
    } 
} 

Example 2: Adding 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?