0

我使用 elementHost 控件在 WinForms 中托管 WPF 控件。当我尝试将 elementHost 的大小(高度)再调整到原始位置时,内部的子控件居中并且周围出现黑色边框。当我尝试修改孩子的大小以匹配主机控件时,它仍然“居中”它并且孩子的一部分被切断并且无法适应。

当表单调整为更大时我的托管控件。

这是我的调整大小代码(在表单调整大小事件处理程序中):

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.

谢谢你的帮助!

4

1 回答 1

1

我之前说过我必须让元素主机填充设计器,然后在表单代码中调整大小,但事实证明这并不是解决问题的原因。在我的一个加载事件中,我将元素主机的子属性的高度设置为一个值,显然这会破坏它。

于 2012-03-14T22:01:20.930 回答