How can I set the WPF webbrowser controls to render pages in iE10 mode or the higher version installed on a machine?
By default, if I create a .net 4 or .net 4.5 application on any machine of OS > Windows 7, it renders the html pages in IE7 mode only. (Please correct me if I am wrong).
How to enable the application to render the html pages in IE10 mode if IE10 is installed on the target machine?
If you don't want to modify the registry and you control the webpage, you can use the
<meta http-equiv="X-UA-Compatible" content="IE=10">
tag in the document's head. I believe it has to be first or immediately following <title> in order to work.
You can use the registry as described here:
http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
EDIT:
for a better explanation you can read this answer too
Will the IE9 WebBrowser Control Support all of IE9's features, including SVG?
For WPF webbrowser control use IE11 mode need , for example, in the constructor of the main window, add the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if(pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
string myProgramName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var currentValue = registrybrowser.GetValue(myProgramName);
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue(myProgramName, 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
If you want to see WPF webbrowser control use IE11 mode in DEBUG mode when run from visual studio, you need to add in the registry all progmam "*". This can be done with the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if (pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
var currentValue = registrybrowser.GetValue("*");
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue("*", 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
Checked for windows 10 and visual studio 2015.
Remark: codes other versions of internet explorer, see here https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
Related
Someday I found that all my WPF applications failed to drag outside of the windows and I cannot resize any windows with real-time preview.
My question is why this happens and how can I solve this?
You can view the animation image showing below:
You can notice that when my cursor is outside the window, the resizing immediately stops and the window keep the size when the cursor first leaving the window there. If the cursor reenters the window area and the window resizing resumes.
Not only all the WPF applications that are written by me, but also the other WPF applications reproduces:
Visual Studio 2017/2019
Snoop
ScreenToGif
Etc.
Non-WPF applications behave correctly.
This phenomenon happens several months ago since my system version was Windows 10 (1809) and now my system version is Windows 10 (1903) and this issue stands still. WPF application embedded from .NET Framework 3.5/4.5/4.8 and .NET Core 3.0.
Update1: I just cleaned all my drives and reinstalled my Windows 10 Professional (1903, Customer version) with some core applications, the issue still exists. The core applications are Chrome, PalmInput IME, iTunes.
Update2: I've written a WPF application handle the window messages. I find that the 49757 message will stop receiving when I'm resizing window outside of it. The message behaves normally on my friend's system.
Update:
As pointed out by members of the WPF team the recommended way of disabling stylus and touch support in WPF is by using the Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport setting in App.config like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
</runtime>
</configuration>
Also note that this is not a solution, rather a work around, that might not be a good fit for all scenarios.
Original:
Markus Eisenstöck found a work around for this issue. By disabling the tablet support in WPF you will experience the expected behavior. I have tested and it works on my machine (Windows 10 version 1903 & .NET Framework 4.6.2):
public static void DisableWpfTabletSupport()
{
// Get a collection of the tablet devices for this window.
TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
if (devices.Count > 0)
{
// Get the Type of InputManager.
Type inputManagerType = typeof(System.Windows.Input.InputManager);
// Call the StylusLogic method on the InputManager.Current instance.
object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
BindingFlags.GetProperty | BindingFlags.Instance |
BindingFlags.NonPublic,
null, InputManager.Current, null);
if (stylusLogic != null)
{
// Get the type of the stylusLogic returned
// from the call to StylusLogic.
Type stylusLogicType = stylusLogic.GetType();
// Loop until there are no more devices to remove.
while (devices.Count > 0)
{
// Remove the first tablet device in the devices collection.
stylusLogicType.InvokeMember("OnTabletRemoved",
BindingFlags.InvokeMethod |
BindingFlags.Instance | BindingFlags.NonPublic,
null, stylusLogic, new object[] { (uint)0 });
}
}
}
}
I have a Windows Phone 8 app that I recently upgraded to 8.1 Silverlight. I'd like to use the new tile templates. Right now I have a ScheduledTaskAgent that uses ShellTile.
In order to use the new live tiles I changed the notification service to WNS in my WMAppManifest.xml. I removed the code to register the old background task and added this code instead:
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "LiveTileBackgroundTask")
{
task.Value.Unregister(true);
}
}
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "LiveTileBackgroundTask";
taskBuilder.TaskEntryPoint = "BackgroundTasks.LiveTileBackgroundTask";
taskBuilder.SetTrigger(new TimeTrigger(15, false));
var registration = taskBuilder.Register();
}
I created a Windows Phone 8.1 Windows Runtime Component called BackgroundTasks that contains a BackgroundTask called LiveTileBackgroundTask:
public sealed class LiveTileBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
const string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideText01'>"
+ "<text id='1'>Text Field 1 (larger text)</text>"
+ "<text id='2'>Text Field 2</text>"
+ "<text id='3'>Text Field 3</text>"
+ "<text id='4'>Text Field 4</text>"
+ "<text id='5'>Text Field 5</text>"
+ "</binding> "
+ "</visual>"
+"</tile>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
TileNotification tileNotification = new TileNotification(doc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
deferral.Complete();
}
}
I added a reference to this assembly in my Windows Phone project.
I also added a Background task declaration in my Package.appxmanifest that has BackgroundTasks.LiveTileBackgroundTask as an Entry point. I selected Timer and System event as supported task types.
When I run the app though, nothing happens. No live tile appears. I ran through the background task and everything goes well without any exceptions.
You say "No live tile appears". The code you've posted does not create a live tile - it just updates one. You have to manually pin it - the primary tile cannot be pinned through code.
If that's not the problem, maybe you're not looking at the wide tile? This template is for a wide tile, so the square tile won't be updated by this. I'd suggest using the NotificationsExtensions library. It was originally for Windows Store apps, but I think it would work for WP as well. (I've used it, but just for a test, not for real, so there may be issues.) It allows you to easily specify the template and params for both wide and square tiles.
And finally, to have a wide tile, you have to manually edit the Package.appxmanifest file. You must add the Wide310x150Logo attribute to the DefaultTile element.
That's all I can think of. Hope it helps.
Continuous background execution is not supported for Silverlight 8.1
apps
Windows Phone 8 apps can continue to run in the background after the
user navigates away from the app under certain conditions. This
feature is not available for Silverlight 8.1 apps. If you need this
feature, you should continue to use a Windows Phone 8 app. For more
information, see Running location-tracking apps in the background for
Windows Phone 8.
Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps
Windows Phone 8.1 Windows Runtime Component can only be used with Windows Phone 8.1 Runtime(Store) app
I am creating one 32bit WPF application.It needs to show created PDF in WebBrowser control.
While doing ,
"WebBrowser.Navigate(new Url("D:\\TestPDF\\MyDocument.pdf"))";
it opens PDF file in Adobe reader window.
My Need is PDF should be opened inside WebBrowser not in Adobe reader window.
I have also tried WebBrowser.NavigateToStream and WebBrowser.Source but its not working.
What can be solution for this? I am looking forward for help.
Have you checked, that you have the Adobe reader installed for the Internet Explorer? You should also verify, that your Internet Explorer is allowed to open PDF-Files embedded.
Sometimes it helpes, to use another Internet Explorer Rendering Engine. This can be archived in with the following code (be warned: Administrator rights are needed for that).
private void CheckAndFixWebBrowserRenderingEngine()
{
RegistryKey baseRegistryKey = Registry.LocalMachine;
string renderingEngineSubKeyString = #"SOFTWARE";
// 64bit operationg systems have another registry path
if (Environment.Is64BitOperatingSystem)
{
renderingEngineSubKeyString += #"\Wow6432Node";
}
renderingEngineSubKeyString += #"\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
var assemblyValueKey = Path.GetFileName(App.ResourceAssembly.Location);
var renderingEngingeValue = 9999; // check other values below
try
{
RegistryKey sk1 = baseRegistryKey.CreateSubKey(renderingEngineSubKeyString);
var value = sk1.GetValue(assemblyValueKey);
if (value == null || value.ToString() != renderingEngingeValue.ToString())
{
sk1.SetValue(assemblyValueKey, renderingEngingeValue);
LogHandler.Instance.Add(string.Format("Did update webbrowser rendering engine from {0} to 9000.", value == null ? "[missing]" : value));
}
}
catch (Exception ex)
{
LogHandler.Instance.Add("Could not check webbrowser rendering engine in registry.");
LogHandler.Instance.Add(ex.ToString(), Logging.LoggingPriorities.Exception);
}
/*
9999 (0x270F)
Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328)
Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
8888 (0x22B8)
Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
*/
}
I have a application previously developed in Visual Studio Express 2010. It uses localized winforms and resx resources used in code.
When the project is opened and compiled using Visual Studio Express 2012 on the same computer the localized strings are not applied, only the default code was found.
The application runs fine and in the winforms designer I can change language to see and edit the localized text of the controls.
I also tried the following code to determine if the languages used were there at runtime, which did report the ones used.
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
try
{
ResourceSet rs = resources.GetResourceSet(culture, true, false);
// or ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture.TwoLetterISOLanguageName), true, false);
if (rs == null)
continue;
string isSupported = (rs == null) ? " is not supported" : " is supported";
Console.WriteLine(culture + isSupported);
}
catch (Exception)
{
Console.WriteLine(culture + " is not available on the machine or is an invalid culture identifier.");
}
}
Still when the application is running all I get is the resources for the default language.
I retrieve the resources using:
ResourceManager resources = new ResourceManager(form.GetType());
form.Text = resources.GetString("$this.Text", lang);
where I have verified that lang is correct, but also using
System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang.Name);
followed by usage of MyLangResxFile.MyStringResource.
The strings returned are still only the default ones.
Might there be changes or limitations in resx localization support between Visual Studio Express 2010 - 2012?
Update:
I noticed that the localisation works if compiled using msbuild.exe from 3.5 but when using 4.0... the localisations are missing as described above.
sorry for "answering" that question but commenting is not working.
I just want to ask if you could solve that issue in the meantime because I have exactly the same issue.
I even noticed that this issue only happens when target framework < 4.0 is selected. For target framework 4.0 and 4.5 localization is working as before in VS 2010...
Trying to test basic browser concepts in a WPF (C#/XAML, .NET 4.0) WebBrowser application. So far, the only problem is programatically zooming. Has anyone had any experience with this?
MSDN lists nothing: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx
Additionally, I have tried various things such as RenderTransform options to no avail. Either this is not possible or not documented. I'm hoping for the latter. Note that a WinForm solution isn't acceptable.
Thanks in advance for any help,
Beems
Maybe you can execute a javascript like this.
document.body.style.zoom = 1.5;
In WPF we can manipulate the document. I Created a Extension Method for you, so you can set the Zoom:
// www.tonysistemas.com.br
public static partial class MyExtensions
{
public static void SetZoom(this System.Windows.Controls.WebBrowser WebBrowser1, double Zoom)
{
// For this code to work: add the Microsoft.mshtml .NET reference
mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";");
}
}
Usage:
WebBrowser1.SetZoom(0.5);
I used bits and pieces from this answer https://stackoverflow.com/a/7326179/17822 to assist with the zoom issue. The key here is the ExecWB method. The zoom on the Windows Desktop is not 1-1 to the zoom on the WebBrowser Control. You will have to play with it. The pseudo-code for the equation looks like this:
zoomLevel = (winDesktopZoom - 100) + _winDesktopZoom + 10
Note that you will need a reference to SHDocVw.dll which can be found in the C:\Windows\SysWOW64 for x64 machines and in C:\Windows\System32 for x86 machines.
This is not pretty, but it is the only thing that I have found, short of upgrading to http://awesomium.com that actually matches IE default zoom settings (which default to the Windows Desktop zoom) to WebBrowser Control. Also note that the Windows Desktop Zoom only exists for Vista, Win 7 and probably 2k8 as well in the Control Panel --> Display, but I didn't check Vista or 2k8. It is not there for XP (any service pack).
To get the Windows Desktop Zoom (this does work on XP for some reason) I did:
var presentSource = PresentationSource.FromVisual(this);
if (presentSource != null && presentSource.CompositionTarget != null
&& presentSource.CompositionTarget.TransformToDevice != null)
{
_zoomPercentage = Convert.ToInt32(100 * presentSource.CompositionTarget.TransformToDevice.M11);
}
This logic is placed in the OnSourceInitialized override for that XAML Window.
You can see this:
http://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/