我正在尝试将一个项目列表绑定到一个TabControl。这些物品看上去如下:
class SciEditor
{
private Scintilla editor = null;
public System.Windows.Forms.Control Editor
{
get { return editor; }
}
private string path = null;
public string ShortName
{
get
{
return null == path ? "New Script" : Path.GetFileNameWithoutExtension(path);
}
}
....在我的主窗口中,这个列表被称为"allScripts“。以下是XAML:
<TabControl Grid.Row="0" Grid.Column="0" Name="tabControl1">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock Text="{Binding ShortName}"/>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<WindowsFormsHost Child="{Binding Editor}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>问题是我不能在WindowsFormsHost中设置“子”,因为
无法在'WindowsFormsHost‘类型的“
”属性上设置“绑定”。“绑定”只能设置在DependencyProperty的DependencyObject上。
如何设置WindowsFormsHost子节点?
编辑:忘了提到,在主窗口构造函数中:
tabControl1.ItemsSource = allScripts;发布于 2012-06-04 17:14:57
将内容模板更改为
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding Editor}" />
</DataTemplate>
</TabControl.ContentTemplate> 并将代码隐藏的Editor属性更改为
public WindowsFormsHost Editor
{
get { return new WindowsFormsHost(){Child=editor}; }
} https://stackoverflow.com/questions/10885211
复制相似问题