Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF选项卡Control/File open需要找到子WindowsFormsHost_Wpf_Windowsformshost - Fatal编程技术网

WPF选项卡Control/File open需要找到子WindowsFormsHost

WPF选项卡Control/File open需要找到子WindowsFormsHost,wpf,windowsformshost,Wpf,Windowsformshost,我试图在WPF中编写一个文本编辑器,但在响应文件->打开操作时,试图在TabControl中找到编辑器的正确实例时遇到问题 选项卡项以编程方式添加,并包含一个WindowsFormsHost实例,该实例反过来允许每个选项卡显示闪烁网WinForms组件提供的编辑器 当选择选项卡并且用户选择File->Open时,我需要根据选项卡选择找到正确的WindowsFormsHost实例,以便将文件加载到正确的闪烁实例中 以前,我在WinForms中只是通过执行以下操作: tabControl.TabPa

我试图在WPF中编写一个文本编辑器,但在响应文件->打开操作时,试图在
TabControl
中找到编辑器的正确实例时遇到问题

选项卡项以编程方式添加,并包含一个
WindowsFormsHost
实例,该实例反过来允许每个选项卡显示闪烁网WinForms组件提供的编辑器

当选择选项卡并且用户选择File->Open时,我需要根据选项卡选择找到正确的WindowsFormsHost实例,以便将文件加载到正确的闪烁实例中

以前,我在WinForms中只是通过执行以下操作:

tabControl.TabPages[tabControl.SelectedIndex].Controls.Find("Scintilla")

这在WPF中是如何工作的?

要跟进我目前使用的解决方案:我决定将
选项卡项
类划分为子类,并保留一个引用WinForms闪烁网控件的附加属性:

public class CustomTabItem : TabItem
{
    public Scintilla EditorControl
    {
        get; set;
    }
}
当我添加新选项卡时,我只需确保
EditorControl
被设置为创建的
scatinlla
的新实例:

var editor = ScintillaFactory.Create();

var tab = new CustomTabItem()
{
     Header = "Untitled",
     Content = new WindowsFormsHost() { Name = "WinformsHost", Child = editor },
     EditorControl = editor
};

tabControl.Items.Add(tab);
tab.Focus();
现在,当引发事件时,我可以查询所选选项卡并将其转换为
CustomTabItem
,以便访问对相应编辑器的引用:

var editor = (tabControl.Items[tabControl.SelectedIndex] as CustomTabItem).EditorControl
editor.Text = "text here";
希望这能帮助别人