This project is read-only.

WPF Tab Control Freezes

Topics: Developer Forum, User Forum
Mar 13, 2013 at 4:05 PM
I am trying to use ScintillaNET in a WPF application. I have a TabControl with an editor in each tab. If I do this:
  1. Create a WindowsFormsHost
  2. Create a Scintilla object and add as WindowsFormsHost.Child
  3. Bind the tab control to Editor member:
private wfh = new WindowsFormsHost();
private Scintilla editor;
public MyClass()
{
    editor = new Scintilla();
    wfh.Child = editor;
    // Set colors and fonts...
}
public Editor
{
    get { return wfh; }
}
And the XAML:
<TabControl Name="tabControl1" IsSynchronizedWithCurrentItem="True" SelectionChanged="tabControl1_SelectionChanged">
    <TabControl.ContentTemplate>
        <DataTemplate>
            <Grid>
                <ContentControl Content="{Binding Editor}" />
            </Grid>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>
If I do it this way, the app freezes when switching tabs. (However, if I put a small pause in "tabControl1_SelectionChanged" it only crashes sometimes.) So I tried dynamically creating the WidowsFormsHost:
public Editor
{
    get {
        return new WindowsFormsHost(){Child = editor};
    }
}
This stops the freezing, but all my formatting is gone. How can I do this properly??
Thanks.
Mar 13, 2013 at 8:11 PM
Well, I've never worked with binding in WPF before, but the way I did it in the WPF branch was by creating a control specifically for ScintillaNET, perhaps your issue is that your creating a new winforms host each time you access the Editor property?