ElementHost 外部的焦点边框未显示
我正在使用 ElementHost 在 WinForms 应用程序中托管 WPF 自定义控件。该控件有一个粗边框,当控件具有焦点时应该可见。边框位于控件“外部”,即具有负边距。
问题是焦点边框永远不会显示。如果我将包含我的控件的填充边框添加到 ElementHost,它就会变得可见。但是,我希望将控件按原样保留在 ElementHost 内部,这样它就不会破坏使用存根之前创建的布局。有什么想法吗?
谢谢。
I'm using an ElementHost to host a WPF custom control in a WinForms app. The control has a thick border which should be visible when the control has focus. The border is "outside" the control, i.e, has a negative margin.
The problem is that the focus border never shows up. If I add a border with padding containing my control to the ElementHost, it gets visible. However, I'd like to have the control inside the ElementHost as it is, so it doesn't break a layout which was made before using a stub. Any idea?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ElementHost 有自己的窗口句柄,它托管其中的所有 WPF 元素。它是一个单独的 WinForms 控件。
一般来说,窗口句柄不能在其边界矩形之外绘制(在本例中,该边界矩形是 ElementHost 相对于其父 WinForms 控件的边界矩形)。
因此,不能在 WPF 元素上使用负边距在 ElementHost 之外进行绘制。您需要在 WinForms 中绘制边框,或者修改布局以使 ElementHost 更大。
The ElementHost has its own window handle, which hosts all of the WPF elements inside it. It's a separate WinForms control.
Generally speaking, a window handle can't draw outside its bounding rectangle (which, in this case, would be the bounding rectangle of the ElementHost, relative to its parent WinForms control).
So no, you can't use a negative margin on your WPF element to draw outside the ElementHost. You'll need to either draw the border in WinForms instead, or modify your layout so that the ElementHost is larger.