DataGridView and Resource
<Window x:Class="HostingAWinFormsControl.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:local="clr-namespace:HostingAWinFormsControl"
Title="HostingAWinFormsControl">
<Grid>
<Grid.Resources>
<local:People x:Key="Family">
<local:Person Name="A" Age="11" />
<local:Person Name="B" Age="12" />
<local:Person Name="C" Age="37" />
</local:People>
</Grid.Resources>
<WindowsFormsHost>
<wf:DataGridView DataSource="{StaticResource Family}" />
</WindowsFormsHost>
</Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
namespace HostingAWinFormsControl {
public class Person {
string name;
public string Name {
get { return name; }
set { name = value; }
}
int age;
public int Age {
get { return age; }
set { age = value; }
}
public Person() { }
public Person(string name, int age) {
this.name = name;
this.age = age;
}
}
public class People : System.Collections.Generic.List<Person> { }
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
//gridView.DataSource = new Person[] {
// new Person("A", 11),
// new Person("B", 12),
// new Person("C", 37)
//};
}
}
}
Related examples in the same category