DataGrid.RowHeaderStyle Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur gaya yang diterapkan ke semua header baris.
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
Nilai Properti
Gaya diterapkan ke semua header baris di DataGrid. Default terdaftar adalah null. Untuk informasi selengkapnya tentang apa yang dapat memengaruhi nilai, lihat DependencyProperty.
Contoh
Contoh berikut menunjukkan cara menampilkan baris bernomor di header baris dengan menerapkan pengikatan dengan pengonversi nilai ke Content properti .DataGridRowHeader Pengonversi dibuat sebagai sumber daya dengan memetakan namespace layanan dan membuat instans kelas. Untuk informasi selengkapnya, lihat Gambaran Umum Pengikatan Data.
<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
Keterangan
Style Terapkan untuk memperbarui tampilan visual semua header baris di DataGrid. Untuk menentukan Style header baris, tentukan TargetType dari DataGridRowHeader.
Anda juga dapat menggunakan RowHeaderStyle properti untuk memperbarui properti apa pun dari DataGridRowHeader.
Style Dapat diterapkan ke semua header baris, atau ke header baris individual. Untuk menerapkan Style ke header individual, atur DataGridRow.HeaderStyle properti , yang lebih diutamakan daripada DataGrid.RowHeaderStyle properti .