我正在尝试将项目列表绑定到TabControl.这些项目看起来像:class SciEditor{private Scintilla editor = null;public System.Windows.Forms.Control Editor{get { return editor; }}private string path = null;pub...
我正在尝试将项目列表绑定到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);
}
}
....
在我的主窗口中,List被称为“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中设置“Child”,因为
A ‘Binding’ cannot be set on the ‘Child’ property of type ‘WindowsFormsHost’. A ‘Binding’ can only be set on a DependencyProperty of a DependencyObject.
如何设置WindowsFormsHost子项?
编辑:忘了提,在主窗口构造函数我有:
tabControl1.ItemsSource = allScripts;
解决方法:
将您的内容模板更改为
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding Editor}" />
</DataTemplate>
</TabControl.ContentTemplate>
并将代码隐藏的Editor属性更改为
public WindowsFormsHost Editor
{
get { return new WindowsFormsHost(){Child=editor}; }
}
本文标题为:c# – 与WindowsFormsHost绑定
基础教程推荐
- C#类和结构详解 2023-05-30
- winform把Office转成PDF文件 2023-06-14
- 一个读写csv文件的C#类 2022-11-06
- C#控制台实现飞行棋小游戏 2023-04-22
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- unity实现动态排行榜 2023-04-27
- C# 调用WebService的方法 2023-03-09
- ZooKeeper的安装及部署教程 2023-01-22
- C# windows语音识别与朗读实例 2023-04-27
- C# List实现行转列的通用方案 2022-11-02