| | |
| | | public static readonly DependencyProperty SelectedColumnProperty = |
| | | DependencyProperty.RegisterAttached("SelectedColumn", typeof(DataGridColumn), typeof(Grid), |
| | | new PropertyMetadata(null)); |
| | | |
| | | public static bool GetShowRowNumber(DependencyObject obj) |
| | | { |
| | | return (bool)obj.GetValue(ShowRowNumberProperty); |
| | | } |
| | | public static void SetShowRowNumber(DependencyObject obj, bool value) |
| | | { |
| | | obj.SetValue(ShowRowNumberProperty, value); |
| | | } |
| | | |
| | | public static readonly DependencyProperty ShowRowNumberProperty = |
| | | DependencyProperty.RegisterAttached("ShowRowNumber", typeof(bool), typeof(DataGrid), |
| | | new PropertyMetadata(false, OnShowRowNumberChanged)); |
| | | |
| | | private static void OnShowRowNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| | | { |
| | | if (d is DataGrid grid) |
| | | { |
| | | if (e.Property == ShowRowNumberProperty) |
| | | { |
| | | if (((bool)e.NewValue)) |
| | | { |
| | | grid.LoadingRow += Grid_LoadingRow; |
| | | } |
| | | else |
| | | { |
| | | grid.LoadingRow -= Grid_LoadingRow; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static void Grid_LoadingRow(object sender, DataGridRowEventArgs e) |
| | | { |
| | | e.Row.Header = e.Row.GetIndex() + 1; |
| | | } |
| | | } |
| | | } |