Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
975 views
in Technique[技术] by (71.8m points)

c# - How to disable drop on wpf webbrowser control

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...