我使用 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.
谢谢你的帮助!