IsFrozen Property

DataGridColumn.IsFrozen Property

.NET Framework (current version)
 

Gets a value that indicates whether the column is prevented from scrolling horizontally.

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

member IsFrozen : bool with get, internal set

Property Value

Type: System.Boolean

true if the column cannot be scrolled horizontally; otherwise, false. The registered default is false. For information about what can influence the value, see DependencyProperty.

IsFrozen cannot be used to freeze a column. Instead, set the FrozenColumnCount property. The leftmost columns up to the column that is specified by the FrozenColumnCount number will freeze in place.

The following example shows how to freeze a column when "Freeze Column" is selected from the ContextMenu. Columns are moved to the left in order to be included in the frozen columns.

<!--Defines the handlers for when the FreezeColumnCommand is executed-->
<Window.CommandBindings>
    <CommandBinding Command="{x:Static local:Window1.FreezeColumnCommand}" Executed="CommandBinding_Executed" />
</Window.CommandBindings>
<!--Defines the context menu for the ColumnHeaders and attaches the FreezeColumnCommand-->
<Window.Resources>
    <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}" />
    </ContextMenu>
</Window.Resources>

<Grid>
    <!--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}" />
            </Style>
        </DataGrid.ColumnHeaderStyle>
    </DataGrid>
</Grid>
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

.NET Framework
Available since 4.0
Silverlight
Available since 2.0
Return to top
Show:
© 2016 Microsoft