WPF 4 DataGrid: Getting the Row Number into the RowHeader

前端 未结 5 1927
日久生厌
日久生厌 2020-12-02 19:02

I am looking to get the row number into the RowHeader of the WPF 4 DataGrid so it has an Excel-like column for the row numbers of the DataGrid.

The solution I\'ve se

5条回答
  •  时光取名叫无心
    2020-12-02 20:07

    Edit: Apparently scrolling changes the index so the binding won't work like that...

    A (seemingly) clean templating solution:
    Xaml:

    
        
            
        
            
                
                    
                        
                    
                
            
    
    

    Converter:

    public class RowToIndexConv : IValueConverter
    {
    
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DataGridRow row = value as DataGridRow;
            return row.GetIndex() + 1;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

提交回复
热议问题