元素主机不会正确调整子项的大小

时间:2012-03-10 04:04:09

标签: c# wpf resize elementhost

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

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

这是我的调整大小代码(以resize事件处理程序的形式):

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.

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

相关问题