WPF中使用DataGridView创建报表控件
直入主题。报表数据是只作显示用的,直接用DataTable比生成ORM集合快,并且高灵活性。以后要修改报表,只要简单修改一下数据库中的视图。
但是WPF中的DataGrid对于数据稍多时,就会很慢。600行的数据显示要半分钟。通过断点查看,发现其实是DataTable绑定到DataGrid时耗时,数据返回到DataTable是很快的。看来要用以前的DataGridView了。用System.Windows.Forms.DataGridView修改后性能大大提高。600行的数据五,六秒。
报表控件的XAML
<
UserControl x:Class=
"WpfApplication1.ReportControl"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable= "d"
d:DesignHeight= "300" d:DesignWidth= "600"
xmlns:winform= "clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
< Grid Background= "DarkGray">
< Grid.RowDefinitions>
< RowDefinition Height= "34">< /RowDefinition>
< RowDefinition>< /RowDefinition>
< /Grid.RowDefinitions>
< StackPanel Grid.Row= "0" Orientation= "Horizontal">
< TextBlock VerticalAlignment= "Center" Text= "{Binding SearchFieldTitle}" Margin= "5">< /TextBlock>
<
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable= "d"
d:DesignHeight= "300" d:DesignWidth= "600"
xmlns:winform= "clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
< Grid Background= "DarkGray">
< Grid.RowDefinitions>
< RowDefinition Height= "34">< /RowDefinition>
< RowDefinition>< /RowDefinition>
< /Grid.RowDefinitions>
< StackPanel Grid.Row= "0" Orientation= "Horizontal">
< TextBlock VerticalAlignment= "Center" Text= "{Binding SearchFieldTitle}" Margin= "5">< /TextBlock>
<