Link to WindowsFormsHost

I am trying to associate a list of items with a TabControl. Elements look like this:

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); } } .... 

In my main window, the List is called "allScripts". Here is the 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> 

The problem is that I cannot install "Child" in WindowsFormsHost because

Binding cannot be set in the Child property of the WindowsFormsHost type. Binding can only be set in the DependencyProperty of a DependencyObject.

How to set a WindowsFormsHost child?

EDIT: forgot to mention, in the main window constructor, I have:

 tabControl1.ItemsSource = allScripts; 
+4
source share
1 answer

Change your content template to

 <TabControl.ContentTemplate> <DataTemplate> <ContentControl Content="{Binding Editor}" /> </DataTemplate> </TabControl.ContentTemplate> 

and change the Editor property of your code to

 public WindowsFormsHost Editor { get { return new WindowsFormsHost(){Child=editor}; } } 
+7
source

Source: https://habr.com/ru/post/1416004/


All Articles