网站框架是什么,阜阳哪里做网站的多,网站色彩搭配案例,网站建设好卖吗在Datagrid中显示行号#xff0c;如果你绑定的datacontext中没有序号#xff0c;又想要显示序号的时候#xff0c;可以按照本文的方法显示喽~效果如下图#xff1a;来看看代码吧~MainWindow.xamlWindow x:Classwpfcore.MainWindowxmlnshttp://schema… 在Datagrid中显示行号如果你绑定的datacontext中没有序号又想要显示序号的时候可以按照本文的方法显示喽~效果如下图来看看代码吧~MainWindow.xamlWindow x:Classwpfcore.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:wpfcore xmlns:controlshttp://metro.mahapps.com/winfx/xaml/controlsmc:IgnorabledBackground#2D2D30SnapsToDevicePixelsTrueFontSize18UseLayoutRoundingTrueTitleMainWindow Width820 Height340GridGrid.RowDefinitionsRowDefinition Height*/RowDefinition Heightauto//Grid.RowDefinitionsDataGrid x:Namedg ItemsSource{Binding Items} RowHeaderWidth50 Grid.Row0 CanUserAddRowsFalse/StackPanel Grid.Row1 OrientationHorizontal VerticalAlignmentCenter HorizontalAlignmentCenterButton Padding18 Content添加 ClickAdd/ButtonButton Padding18 Content删除 ClickRemove/Button/StackPanel/Grid
/Window
MainWindow.cs代码using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;namespace wpfcore
{public partial class MainWindow : Window{public ObservableCollectionItem Items { get; set; }public MainWindow(){InitializeComponent();DataContext this;Items new ObservableCollectionItem(){new Item{Age18,NameWPF UI},new Item{Age18,Name大佬},new Item{Age18,Name牛逼},new Item{Age18,Namewocao666},};dg.LoadingRow (s,e)e.Row.Header 行号 e.Row.GetIndex();}private void Add(object sender, RoutedEventArgs e){Items.Add(new Item() { Age 18, Name 6666 });}private void Remove(object sender, RoutedEventArgs e){Items.RemoveAt(Items.Count - 1);}}public class Item{public int Age { get; set; }public string Name { get; set; }}
}思路在LoadingRow事件中设置Header如果喜欢点个赞呗~