以下的資料來源是從這個網站:
================================================================
How to use a DataGrid or DataGridView in a WPF app
1.add references to these two assemblies:
System.Windows.Forms (since that refers to the controls we're building a wrapper for.)
WindowsFormsIntegration (which holds the WindowsFormsHost control we'll use.)
2.add these two namespace declaration attributes to that element:
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=
WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
3.make use of the new namespace and add in a WindowsFormsHost, and a single WinForms control inside, like this:
<wfi:WindowsFormsHost Height="100" Width="200">
<wf:DataGrid x:Name="myDG"></wf:DataGrid>
</wfi:WindowsFormsHost>
==========================================================
整個範例程式,WindowsFormsHost加入DataGrid如下:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
<Grid>
<wfi:WindowsFormsHost Height="100" Width="200">
<wf:DataGrid x:Name="myDG"></wf:DataGrid>
</wfi:WindowsFormsHost>
</Grid>
</Window>
留言列表