cat
cat

Reputation: 530

Element host doesn't resize child properly

I'm hosting a WPF control in WinForms using the elementHost control. When I try to resize the elementHost (in height) any further then the orignal position, the child control inside is centered and black borders appear around it. When I try to modify the child's size to match the host control, it still "centers" it and part of the child is cut off and cant fit.

My hosted control when the form is resized to be bigger.

Here is my resize code (which is in the form resize event handler):

elementHost1.Height = ClientSize.Height - h;
elementHost1.Width = ClientSize.Width - w;
(elementHost1.Child as WPFCodeBox).textEditor.Height = ClientSize.Height - h;
(elementHost1.Child as WPFCodeBox).textEditor.Width = ClientSize.Width - w;
(elementHost1.Child as WPFCodeBox).Border.Width = ClientSize.Width - w;
(elementHost1.Child as WPFCodeBox).Border.Height = ClientSize.Height - h;

Where h is the distance from the bottom of the form to the bottom of the element host
same for w but in width.

Thanks for any help!

Upvotes: 0

Views: 2191

Answers (1)

cat
cat

Reputation: 530

I previously said I had to make the elementhost fill the designer, then resize in the form code, but as it turns out that wasn't what fixed it. In one of my load events, I was setting the elementhost's child property's height to a value, and apparently that breaks it.

Upvotes: 1

Related Questions