views:

50

answers:

2

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.

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" />

..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?

A: 

I tried a couple of things, but it looks like the WebBrowser control asserts its primacy over and above anything the layout engine wants. It doesn't obey or even really sit in the visual tree, except for control siting. Panel.ZIndex had no effect, etc.

Perhaps a different HTML layout control would be in order, one that behaves better than the ActiveX IE 6/7/8 interface here:

http://stackoverflow.com/questions/790542/replacing-net-webbrowser-control-with-a-better-browser-like-chrome

Rob Perkins
I need the control to be IE as I am doing interop between managed code and a COM component in the loaded document. The COM component only works in IE. The fact that the wpf webbrowser has such a security hole in it is crazy!
Fraser
A: 

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.

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;">

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">
Fraser