다음을 통해 공유


DataGridColumn.Visibility Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the visibility of the column.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
Public Property Visibility As Visibility
public Visibility Visibility { get; set; }
<sdk:dataGridColumn Visibility="Visible"/>
-or-
<sdk:dataGridColumn Visibility="Collapsed"/>

XAML Values

Property Value

Type: System.Windows.Visibility
An enumeration value that specifies the column visibility. The default is Visible.

Examples

The following code example demonstrates how to set the Visibility property. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.

Private Sub cbHideColumn_Changed(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim cb As CheckBox = sender
    If Me.dataGrid1 IsNot Nothing Then
        If cb.IsChecked = True Then
            Me.dataGrid1.Columns(0).Visibility = Windows.Visibility.Collapsed
        ElseIf cb.IsChecked = False Then
            Me.dataGrid1.Columns(0).Visibility = Windows.Visibility.Visible
        End If
    End If
End Sub
private void cbHideColumn_Changed(object sender, RoutedEventArgs e)
{
    CheckBox cb = sender as CheckBox;
    if (this.dataGrid1 != null)
    {
        if (cb.IsChecked == true)
            this.dataGrid1.Columns[0].Visibility = Visibility.Collapsed;
        else if (cb.IsChecked == false)
            this.dataGrid1.Columns[0].Visibility = Visibility.Visible;
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.