DataGrid.RowHeaderStyle Propiedad

Definición

Obtiene o establece el estilo aplicado a todos los encabezados de fila.

public:
 property System::Windows::Style ^ RowHeaderStyle { System::Windows::Style ^ get(); void set(System::Windows::Style ^ value); };
public System.Windows.Style RowHeaderStyle { get; set; }
member this.RowHeaderStyle : System.Windows.Style with get, set
Public Property RowHeaderStyle As Style

Valor de propiedad

Style

Estilo que se aplica a todos los encabezados de fila de DataGrid. El valor predeterminado registrado es null. Para obtener más información sobre lo que puede afectar al valor, vea DependencyProperty.

Ejemplos

En el ejemplo siguiente se muestra cómo mostrar filas numeradas en el encabezado de fila aplicando un enlace con un convertidor de valores a la Content propiedad de DataGridRowHeader. El convertidor se crea como un recurso mediante la asignación del espacio de nombres y la creación de una instancia de la clase . Para obtener más información, consulte Introducción al enlace de datos.

<Window.Resources>
    <local:ConvertItemToIndex x:Key="IndexConverter"/>     
</Window.Resources>
<Grid>
    <DataGrid Name="DG1" ItemsSource="{Binding}" CanUserAddRows="False" CanUserDeleteRows="False" >
        <!--Bind the Content property of the RowHeaderStyle to the Converter to create numbered rows-->
        <DataGrid.RowHeaderStyle>
            <Style TargetType="{x:Type DataGridRowHeader}">
                <Setter Property="Content" Value="{Binding Converter={StaticResource IndexConverter}}" />
            </Style>
        </DataGrid.RowHeaderStyle>
    </DataGrid>
</Grid>
public class ConvertItemToIndex : IValueConverter
{
    #region IValueConverter Members
    //Convert the Item to an Index
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        try
        {
            //Get the CollectionView from the DataGrid that is using the converter
            DataGrid dg = (DataGrid)Application.Current.MainWindow.FindName("DG1");
            CollectionView cv = (CollectionView)dg.Items;
            //Get the index of the item from the CollectionView
            int rowindex = cv.IndexOf(value)+1;

            return rowindex.ToString();
        }
        catch (Exception e)
        {
            throw new NotImplementedException(e.Message);
        }
    }
     //One way binding, so ConvertBack is not implemented
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}
Public Class ConvertItemToIndex
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            'Get the CollectionView from the DataGrid that is using the converter 
            Dim dg As DataGrid = DirectCast(Application.Current.MainWindow.FindName("DG1"), DataGrid)
            Dim cv As CollectionView = DirectCast(dg.Items, CollectionView)
            'Get the index of the item from the CollectionView 
            Dim rowindex As Integer = cv.IndexOf(value) + 1

            Return rowindex.ToString()

        Catch e As Exception
            Throw New NotImplementedException(e.Message)
        End Try
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class

Comentarios

Aplique para Style actualizar la apariencia visual de todos los encabezados de fila de DataGrid. Para definir un Style para un encabezado de fila, especifique un TargetType de DataGridRowHeader.

También puede usar la RowHeaderStyle propiedad para actualizar cualquier propiedad de DataGridRowHeader.

Se Style puede aplicar a todos los encabezados de fila o a un encabezado de fila individual. Para aplicar un Style objeto a un encabezado individual, establezca la DataGridRow.HeaderStyle propiedad , que tiene prioridad sobre la DataGrid.RowHeaderStyle propiedad .

Se aplica a

Consulte también