DataGridColumn.IsFrozen DataGridColumn.IsFrozen DataGridColumn.IsFrozen DataGridColumn.IsFrozen Property


Obtiene un valor que indica si la columna no se puede desplazar horizontalmente.Gets a value that indicates whether the column is prevented from scrolling horizontally.

 property bool IsFrozen { bool get(); };
public bool IsFrozen { get; }
member this.IsFrozen : bool
Public ReadOnly Property IsFrozen As Boolean

Valor de propiedad

Es true si la columna no se puede desplazar horizontalmente; en caso contrario, es false.true if the column cannot be scrolled horizontally; otherwise, false. El valor predeterminado registrado es false.The registered default is false. Para obtener información sobre lo que puede afectar al valor, vea DependencyProperty.For information about what can influence the value, see DependencyProperty.


En el ejemplo siguiente se muestra cómo inmovilizar una columna cuando se selecciona "inmovilizar columna" en la ContextMenu.The following example shows how to freeze a column when "Freeze Column" is selected from the ContextMenu. Las columnas se mueven hacia la izquierda para que se incluyan en las columnas inmovilizadas.Columns are moved to the left in order to be included in the frozen columns.

<!--Defines the handlers for when the FreezeColumnCommand is executed-->
    <CommandBinding Command="{x:Static local:Window1.FreezeColumnCommand}" Executed="CommandBinding_Executed" />
<!--Defines the context menu for the ColumnHeaders and attaches the FreezeColumnCommand-->
    <ContextMenu x:Key="ColumnHeaderMenu" IsEnabled="True"  >
        <MenuItem Header="Freeze Column" IsEnabled="True" Command="{x:Static local:Window1.FreezeColumnCommand}"
                  CommandTarget="{Binding RelativeSource={RelativeSource AncestorType=Popup}, Path=PlacementTarget}" 
                  CommandParameter="{Binding ElementName=DG1, Path=CurrentColumn.DisplayIndex}" />

    <!--Creates a new DataGrid with a context menu for the column headers-->
    <DataGrid Name="DG1" ItemsSource="{Binding}"  >
        <DataGrid.ColumnHeaderStyle >
            <Style TargetType="DataGridColumnHeader">
                <Setter Property="ContextMenu" Value="{StaticResource ColumnHeaderMenu}" />
public partial class Window1 : Window
    public static RoutedUICommand FreezeColumnCommand = new RoutedUICommand();


    public Window1()
        //GetData connects to the database and returns the data in a table.
        AdventureWorksLT2008DataSet.SalesOrderDetailDataTable dt = GetData();

        DG1.DataContext = dt;
Class Window1
    Public Shared FreezeColumnCommand As New RoutedUICommand()

    Public Sub New()

        'GetData connects to the database and returns the data in a table.
        Dim dt As AdventureWorksLT2008DataSet.SalesOrderDetailDataTable = GetData()

        DG1.DataContext = dt
    End Sub
    private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
       //Get the column header that started the command and move that column left to freeze it.
       System.Windows.Controls.Primitives.DataGridColumnHeader header = (System.Windows.Controls.Primitives.DataGridColumnHeader)e.OriginalSource;
       if (header.Column.IsFrozen ==true)
           header.Column.DisplayIndex = DG1.FrozenColumnCount;

Private Sub CommandBinding_Executed(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    'Get the column header that started the command and move that column left to freeze it.
    Dim header As System.Windows.Controls.Primitives.DataGridColumnHeader = DirectCast(e.OriginalSource, System.Windows.Controls.Primitives.DataGridColumnHeader)
    If header.Column.IsFrozen = True Then
        Exit Sub
        header.Column.DisplayIndex = DG1.FrozenColumnCount
        DG1.FrozenColumnCount += 1

    End If
End Sub


IsFrozenno se puede usar para inmovilizar una columna.IsFrozen cannot be used to freeze a column. En su lugar, establezca FrozenColumnCount la propiedad.Instead, set the FrozenColumnCount property. Las columnas situadas más a la izquierda hasta la columna especificada FrozenColumnCount por el número se congelarán en su lugar.The leftmost columns up to the column that is specified by the FrozenColumnCount number will freeze in place.

Se aplica a

Consulte también: