3

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?

Migwell
  • 14,206
  • 17
  • 65
  • 122
  • 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 works – Kirill Lykov Dec 21 '10 at 12:20
  • Have you set any width and height or set VerticalAlignment and HorizontalAlignment on the wpf control? – Rune Andersen Dec 21 '10 at 11:30
  • 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 Dec 21 '10 at 11:37
  • 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 Dec 21 '10 at 11:52
  • I tested with the button, and that worked fine. So it might be AvalonEdit behaviour... – Migwell Dec 21 '10 at 23:47
  • Also just confirmed that the Width/Height and ActualWidth/Height are not NaN, I was just checking before they had actually been loaded. – Migwell Dec 22 '10 at 06:54
  • What happens if you resize the winforms window? It triggers a refresh - if it has an effect you could add a refresh. You could also try manually calling Measure and Arrange on AvalonEdit. – Rune Andersen Dec 22 '10 at 10:02

1 Answers1

0

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.

Migwell
  • 14,206
  • 17
  • 65
  • 122