DataGrid.RowHeaderStyle 속성

정의

모든 행 머리글에 적용되는 스타일을 가져오거나 설정합니다.

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

속성 값

Style

DataGrid에 있는 모든 행 머리글에 적용되는 스타일입니다. 등록된 기본값은 null입니다. 값에 영향을 줄 수 있는 요소에 대한 자세한 내용은 DependencyProperty를 참조하십시오.

예제

다음 예제에서는 값 변환기가 있는 바인딩을 속성에 적용하여 행 머리글에 번호가 Content DataGridRowHeader매겨진 행을 표시하는 방법을 보여 줍니다. 변환기는 네임스페이스를 매핑하고 클래스의 인스턴스를 만들어 리소스로 만들어집니다. 자세한 내용은 데이터 바인딩 개요를 참조하세요.

<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

설명

Apply a Style to update the visual appearance of all the row headers in the DataGrid. 정의 하는 Style 행 머리글에 대 한 지정을 TargetTypeDataGridRowHeader합니다.

속성을 사용하여 모든 RowHeaderStyle 속성을 업데이트 DataGridRowHeader할 수도 있습니다.

Style 개별 행 머리글 또는 모든 행 머리글에 적용할 수 있습니다. 적용할를 Style 개별 헤더를 설정 합니다 DataGridRow.HeaderStyle 보다 우선적으로 사용 하는 속성은 DataGrid.RowHeaderStyle 속성입니다.

적용 대상

추가 정보