3
votes

I have a WPF control (the ICSharpCode.AvalonEdit.TextEditor) in a Winforms project inside an ElementHost.

I have confirmed with the debugger that the TextEditor is actually set as the child of the ElementHost, and all its properties are being set correctly, it's just invisible and unable to be interacted with (as if you had set the IsVisible property to false).

The ElementHost shows up, and I can interact with that, but it's rather that the Child control is not visible. I've checked that the TextEditor's Visiblity and IsVisible properties are as they should be.

I have never actually written a WPF app, so try any suggestions no matter how simple that could mean that my WPF control is invisible. It could be to do with the ElementHost, the control itself, or to do with specific AvalonEdit behaviour.

Any suggestions?

1
Have you set any width and height or set VerticalAlignment and HorizontalAlignment on the wpf control?Rune Andersen
Vertical and Horizontal Alignment are both set to Strech, but both Width and Height are set to NaN (lol). How did that happen? How do I make the TextBox resize to fit the ElementHost?Migwell
Did you try inserting a simple control - like a button - in your elementhost? Winforms can do strange things :) And at what point do you insert the elementhost - in the constructor, or in some strange event (like OnLayout, OnPaint etc.)Rune Andersen
I tried to have the same problem you have. I created a new Winforms application and added HostElement in the Form. In the code behind I wrote TextEditor te = new TextEditor(); this.elementHost1.Child = te; And it worksKirill Lykov
I tested with the button, and that worked fine. So it might be AvalonEdit behaviour...Migwell

1 Answers

0
votes

It turns out that I was setting that margin property of the TextEditor to a number far too high like this:

TextEditor.Margin = 1000;

And this margin was covering the entire control.