我正在尝试将项目列表绑定到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绑定
				
        
 
            
        - Unity Shader实现模糊效果 2023-04-27
 - WPF使用DrawingContext实现绘制刻度条 2023-07-04
 - 如何使用C# 捕获进程输出 2023-03-10
 - Unity3D实现渐变颜色效果 2023-01-16
 - 在C# 8中如何使用默认接口方法详解 2023-03-29
 - .NET CORE DI 依赖注入 2023-09-27
 - Oracle中for循环的使用方法 2023-07-04
 - user32.dll 函数说明小结 2022-12-26
 - C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
 - c# 模拟线性回归的示例 2023-03-14
 
						
						
						
						
						
				
				
				
				