2012-03-10 53 views
0

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

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

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

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. 

感谢您的帮助!

+0

嗨艾丹 - 如果你已经解决了你自己的问题,请张贴解决方案作为答案,并在时间过后,将其标记为已接受。这样,问题实际上会在整个网站上“回答”。 – 2012-03-14 21:55:01

+0

将您的解决方案放入答案中并接受它。 – EricSchaefer 2012-03-14 21:56:04

回答

1

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

相关问题