まあ、あなたは先に進んでそれを行うことができると思います。
この小さなコードは、私が信じていることをほとんど実行します..
XAML:
<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl Content="{Binding UI}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
分離コード:
public partial class MainWindow : Window
{
public List<Model> Items { get; set; }
public MainWindow()
{
InitializeComponent();
var textblock = new TextBlock();
textblock.Text = "I'm a textblock";
var button = new Button();
button.Content = "I'm a button";
var combobox = new ComboBox();
combobox.Items.Add("Item1");
combobox.Items.Add("Item2");
this.Items = new List<Model>(new[] {
new Model(textblock),
new Model(button),
new Model(combobox)
});
this.DataContext = this;
}
public class Model
{
public UIElement UI { get; set; }
public Model(UIElement ui)
{
this.UI = ui;
}
}
}