Silverlight DataGrid赋数据源自动生成列表
不知道大家对DataGrid赋数据源清楚不,我做的时候老是不出来效果 最后终于查到原因了
通过 PagedCollectionView 实现了 下边是代码
界面xml
<sdk:DataGrid AutoGenerateColumns="False" Grid.Row="1" Name="dgRecord" ColumnHeaderHeight="20" FontSize="11" IsReadOnly="True">
<sdk:DataGrid.BorderBrush>
<LinearGradientBrush>
<GradientStop Color="#FFA3AEB9" Offset="0" />
<GradientStop Color="#FF8399A9" Offset="0.375" />
<GradientStop Color="#FF718597" Offset="0.375" />
<GradientStop Color="#FFC1CAD1" Offset="1" />
</LinearGradientBrush>
</sdk:DataGrid.BorderBrush>
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="彩种" Binding="{Binding LotteryName}" Width="80" />
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="订单名称" Binding="{Binding ProgramName}" Width="120" />
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="期次" Binding="{Binding CNumber}" Width="100" />
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="投注内容" Binding="{Binding BettingProgram}" Width="150" />
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="下单时间" Binding="{Binding AddTime}" Width="120" />
<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="投注金额" Binding="{Binding BettingMoney}" Width="80" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
代码
PagedCollectionView view = new PagedCollectionView(orderList);
this.betRecordList.dgRecord.ItemsSource = view;
其中 orderList是泛型集合