I need to have tab view of the new IE versions in the WPF WebBrowser
control. How can I achieve it?
Do I have to use TabControl
and host WebBrowser
control in each of its tab items? I thought there could be some better way to have a Tabbed view in WebBrowser
control itself because some of the features are very conveniently managed by the IE plugin itself such as "Open in Tab" option, "Drag and Arrange Tab order", open new tab with default url etc.
If I go the TabControl
way then I will have to recreate all this functionalitites. Any wild inputs are welcome. :-)
Thx.
EDIT
Solution to achieve how to enable "Open in Tab" Right Click option in your WebBrowser
control.
using System;
using System.Runtime.InteropServices;
namespace TabbedBro开发者_运维百科wsing
{
public enum INTERNETFEATURELIST
{
FEATURE_OBJECT_CACHING = 0,
FEATURE_ZONE_ELEVATION = 1,
FEATURE_MIME_HANDLING = 2,
FEATURE_MIME_SNIFFING = 3,
FEATURE_WINDOW_RESTRICTIONS = 4,
FEATURE_WEBOC_POPUPMANAGEMENT = 5,
FEATURE_BEHAVIORS = 6,
FEATURE_DISABLE_MK_PROTOCOL = 7,
FEATURE_LOCALMACHINE_LOCKDOWN = 8,
FEATURE_SECURITYBAND = 9,
FEATURE_RESTRICT_ACTIVEXINSTALL = 10,
FEATURE_VALIDATE_NAVIGATE_URL = 11,
FEATURE_RESTRICT_FILEDOWNLOAD = 12,
FEATURE_ADDON_MANAGEMENT = 13,
FEATURE_PROTOCOL_LOCKDOWN = 14,
FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15,
FEATURE_SAFE_BINDTOOBJECT = 16,
FEATURE_UNC_SAVEDFILECHECK = 17,
FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18,
FEATURE_TABBED_BROWSING = 19,
FEATURE_SSLUX = 20,
FEATURE_DISABLE_NAVIGATION_SOUNDS = 21,
FEATURE_DISABLE_LEGACY_COMPRESSION = 22,
FEATURE_FORCE_ADDR_AND_STATUS = 23,
FEATURE_XMLHTTP = 24,
FEATURE_DISABLE_TELNET_PROTOCOL = 25,
FEATURE_FEEDS = 26,
FEATURE_BLOCK_INPUT_PROMPTS = 27,
FEATURE_ENTRY_COUNT = 28
}
public enum DWFLAGS
{
SET_FEATURE_ON_THREAD = 0x00000001,
SET_FEATURE_ON_PROCESS = 0x00000002,
SET_FEATURE_IN_REGISTRY = 0x00000004,
SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008,
SET_FEATURE_ON_THREAD_INTRANET = 0x00000010,
SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020,
SET_FEATURE_ON_THREAD_INTERNET = 0x00000040,
SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080
}
public static class IEFeatureSetBehavior
{
[DllImport("urlmon.DLL")]
public static extern Int32 CoInternetSetFeatureEnabled(INTERNETFEATURELIST featureEntry, Int32 dwFlags, bool fEnable);
[DllImport("urlmon.DLL")]
public static extern Int32 CoInternetIsFeatureEnabled(INTERNETFEATURELIST featureEntry, Int32 dwFlags);
public static void EnabledTabbedBrowsing()
{
var lr = 0;
var featureToEnable = INTERNETFEATURELIST.FEATURE_TABBED_BROWSING;
if (CoInternetSetFeatureEnabled(featureToEnable, (Int32)DWFLAGS.SET_FEATURE_ON_PROCESS, true) == 0)
{
if (CoInternetIsFeatureEnabled(featureToEnable, (Int32)DWFLAGS.SET_FEATURE_ON_PROCESS) != 0)
{
lr = 2;
}
else
{
lr = 1;
}
}
}
}
}
We just need to call the
IEFeatureSetBehavior.EnabledTabbedBrowsing();
in your Window's constrcutor. All the WebBrowser
controls will now enable the Open in Tab
right click option \ wheel click \ Ctrl + Click.
But this will not host a aTabControl in your WebBrowser
control. The option opens the IE browser instance with the relevant link opened as a Tab. :(
But nonetheless there is another way. We can be aware of the tabbed browsing request. If a user tries to call tabbed browsing, an event is raised by the WebBrowser
control. We can handle this event and based on that create a new TabItem
with another web browser control in it which is part of a WPF TabControl
that wraps our previous web browser control.
Cheers.
:-)
FEATURE_TABBED_BROWSING
The way you suggested (putting the WebBrowser
control into a TabControl
) is probably as good as it gets.
That beeing said, you will still be running into walls quickly because the WebBrowser control is very limited. All you can bassically do with it, is open a URL and scroll and click in it. You don't get APIs for the DOM which you'd need if you would like to provide a context menu action like "Open in new tab".
That also beeing said, you might want to have a look at Awsomium wich is a much more sophisticated web browser control but unfortunately might not be free for you.
精彩评论