WPF:InkCanvas +框架
我需要在 html 页面上绘制。页面显示在 Frame 元素中。 问题是 InkCanvas 不能与 Frame 一起使用。 我尝试插入 TextBlock 而不是 Frame - 绘画作品。
不工作:
<Frame Grid.Row="1" Source="http://google.com/"></Frame>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
工作:
<TextBlock Grid.Row="1" Margin="10" Text="Some text"></TextBlock>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
I need to draw over the html page. Page displayed in a Frame element.
The problem is that InkCanvas does not work with Frame.
I tried to insert TextBlock instead of Frame - painting works.
Does not work:
<Frame Grid.Row="1" Source="http://google.com/"></Frame>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
Work:
<TextBlock Grid.Row="1" Margin="10" Text="Some text"></TextBlock>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 Frame 控件导航到 HTML 内容时,Frame 控件在内部实例化本机 WebBrowser ActiveX 控件。这涉及到 HWND 互操作。因此,“空域问题”开始发挥作用。这基本上意味着 WPF 内容不能与 AcitveX HWND 重叠。您可以通过将覆盖层包装到另一个 HWND 中(例如使用 Winfows Forms 和 ElementHost)来部分解决此问题。但此解决方案不允许您在叠加层中具有透明度。
您可以尝试的另一个技巧是使用 WindowsFormsHost 托管Windows 窗体浏览器控件< /a> 而不是使用框架。
最后但并非最不重要的一点是,您可以使用 Chromium WPF Webbrowser Control 而不是 Frame 控件(如果您负担得起的话)。它基于 Awesomium 库。不幸的是,仅免费用于非商业用途。这是唯一允许您使用所有高级 WPF 功能的解决方案,例如转换(旋转、倾斜等)、位图效果或透明度等。将其他两个解决方案的宽度绑定到固定的不透明矩形。
When the Frame control navigates to HTML content, the Frame control internally instantiates the native WebBrowser ActiveX control. This involves HWND interop. As a result of that the "airspace proplem" comes into play. It basically means that no WPF content can overlap that AcitveX HWND. You can partly work around this propblem by wrapping the overlay into another HWND (e.g. using Winfows Forms and ElementHost). But this solution will not allow you to have transparency in the overlay.
Another trick you could try is to use the WindowsFormsHost to host the Windows Forms Browser Control instead of using a Frame.
Last but not least you could use the Chromium WPF Webbrowser Control instead of the Frame control if you can afford it. It is based on the Awesomium library. Which unfortunately is only free for non commercial use. This is the only solution that allows you to use all the advanced WPF goodies like transformation (rotation, skew etc.), bitmapeffects or transparency etc. Width the other two solutions you are bound to a fixed opaque rectangle.