后台代码 Window1.xaml.cs

 

 
    
  1. private void dataGrid1_Loaded(object sender, RoutedEventArgs e) 
  2.         { 
  3.            DataTable dt= SqlHelper.ExecuteTable("select * from T_user"); 
  4.             
  5.            dataGrid1.ItemsSource = dt.DefaultView; 
  6.         } 

前台使用dataGrid控件绑定

 

 
    
  1.  
  2.        "False" Height="200" HorizontalAlignment="Left" Margin="37,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" ItemsSource="{Binding}" Loaded="dataGrid1_Loaded"
  3.             
  4.                "姓名" Binding="{Binding Path=name}"
  5.                "性别" Binding="{Binding Path=sex}"
  6.                "住址" Binding="{Binding Path=address}"
  7.                 
  8.             
  9.         
  10.