如何禁用WPF WebBrowser控件下降 [英] How to disable drop on wpf webbrowser control

查看:300
本文介绍了如何禁用WPF WebBrowser控件下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何禁用文件的滴下在System.Windows.Controls.WebBrowser?从文档它似乎,这种行为应该默认被禁用,因为它是从UIElement.AllowDrop财产继承。

How can I disable dropping of files on a System.Windows.Controls.WebBrowser? From the documentation it would seem that this behaviour should be disabled by default as it is inherited from the UIElement.AllowDrop Property.

不过DY默认我可以拖放到一个WebBrowser控件拖放文件。继这似乎我不能禁用此所谓无违约行为。例如,如果我明确的属性值设置为false XAML

However dy default I can drag and drop files on to a WebBrowser control. Further to this it seems I can't disable this supposedly none-default behaviour. For example if I explicitly set the value of the property to false in XAML

<WebBrowser Name="webBrowser1" AllowDrop="False" />

..和/或code-背后,即

..and/or in code-behind, i.e.

webBrowser1.AllowDrop = false;

然后我还可以将文件拖放到控制。我怎样才能禁用此行为并删除它创建的安全风险?

Then I can still drag and drop files onto the control. How can I disable this behaviour and remove the security risk it creates?

推荐答案

好吧小时的玩这个小时后我想出了一个解决方案,工程。因为我使用的是标准的web浏览器WP​​F我知道我还可以使用扩展事件属性,微软的Internet Explorer介绍。

Ok after hours and hours of playing with this I have come up with one solution that works. Because I am using the standard WPF webbrowser I know I can also use the "Extended Event Attributes" that Microsoft introduced for Internet Explorer.

我使用禁用下探文件到该控件的事件是ondragover。基本上我只是取消该事件时,它偏偏喜欢这样。

The event I am using to disable dropping files onto the control is ondragover. Essentially I just cancel the event whenever it happens like so.

<body ondragover="window.event.returnValue=false;">

这是不甚理想 - 但什么是好关于这项技术的是,它允许对不从托管code直接提供其他属性进行设置一大堆。用于滚动的状态,这是不是在管理code露出,可以设置这样

This is not really ideal - but what is good about this technique is that it allows for a whole host of other properties to be set that are not available directly from managed code. For the scrollbar state, which is not exposed in managed code, can be set this way.

<body scroll="no">

这篇关于如何禁用WPF WebBrowser控件下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆