I am working on a WPF app which has Web Browser in one of its views. When I run the Application, It works fine but the Web Browser Control sits on top of my wpf region. I know this is something to do with the AirSpace issue. Is there any possible way to get over it? Any help will be appreciated.
Thanks
The issue was not solved in WPF 4.5.
There were some information in net such the below mentioned properties would be available with the 4.5 version of web browser control, however the plan has been dropped. So you need to handle the airspace issue by yourself.
WebBrowser.CompositionMode = System.Windows.Interop.CompositionMode.Full;
WebBrowser.IsRedirected = true;
The workaround that you could do is by making the height of the web browser control to zero, when some other control comes in front of Web browser control.
Find sample code below,
Assume, you have a web browser control in Mainwindow. When you perform some action,, eg: click a button you have another user control which comes above MainWindow. However, because of Airspace issue the web browser doesn't sit in its parent control and comes on top of your control.
FIX:
The standard fix is you can set the height of web browser to zero when you trigger some other control over it depends upon your scenario. Below, there is a sample implementation.
In MainWindow.Xaml include the events.
Activated="Window_Activated"
Deactivated="Window_Deactivated"
In Xaml.cs handle the scenario by setting the height.
private void Window_Activated(object sender, EventArgs e)
{
wb.Height = double.NaN;
}
private void Window_Deactivated(object sender, EventArgs e)
{
wb.Height = 0;
}
Here is technical information for why this happens.
Some tips and suggestions to get rid of that
This is a known problems, as Neeraj posts. But with WPF 4.5 this seems to be solved, so if you don't mind using the beta version you should download Visual Studio 11.
Try Chris84898's AirspaceFixer project.
https://github.com/chris84948/AirspaceFixer
You just host the problematic control inside a panel, and it does the heavy lifting for you.
XAML:
<asf:AirspacePanel x:Name="ap"
FixAirspace="{Binding FixAirspace}"
Grid.Column="0" Grid.Row="1" >
<WebBrowser x:Name="browser" Navigated="Browser_Navigated" />
</asf:AirspacePanel>
To temporarily "FixAirspace" in code (or through dependency property changes):
ap.FixAirspace = true;
// Display a dialog or whatever
ap.FixAirspace = false;
There is a NuGet package for it as well.
Related
I have issues with initializing CefSharp3. The control give a blank page after initializing.
I follow the instructions from CefSharp Wiki page (https://github.com/cefsharp/CefSharp/wiki/Quick-Start and http://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application)
The problem is that when I build the application for x64 i get a blank page, but it works fine in x86.
The only code in my WinForms project is this:
public ChromiumWebBrowser chromeBrowser;
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
// Initialize cef with the provided settings
Cef.Initialize(settings);
// Create a browser component
chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com");
// Add it to the form and fill it to the form window.
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
public Form1()
{
InitializeComponent();
// Start the browser after initialize global component
InitializeChromium();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
I also tried adding a panel, and initializing ChromiumBrowser in the panel with panel1.Controls.Add(chromeBrowser) instead of this.Controls.add(chromeBrowser), but the issue is still there.
I found this in the troubleshooting section at CefSharp wiki:
https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting
b) The developer tools. Add a button to your form and make a call to "browser.ShowDevTools()". If you can see a document has loaded and you have a DOM in there, then your problem is a display output one and your most likely problem is one of not setting 'Dock' correctly, or some other setting is causing the browser to render offscreen/headless. If you get a blank tool window, or no tool window at all, then CefSharp has failed to initialize correctly, so you have a set-up issue to troubleshoot.
This is exactly the symptoms that I experience.
I tried creating the same project on my laptop (MacBook Pro with Win7, VS2013 and .NET 4.5.2) and it worked like a charm. This means something is up with my workstation (win10, VS2015 .NET 4.5.3).
Any ideas?
This appears to be a bug in the latest build. The solution for now is to use the v51.0.0 build.
You can do this quite easily in the NuGet package manager in VS2015, or if your using VS2013, use the "--version 51.0.0" option when installing cefsharp from the package manager command line.
The issue for the problem is here:
https://github.com/cefsharp/CefSharp/issues/1870
Keep an eye on the issue for future solutions.
Update 28/11/2016
This is a bug in the current V53 release of CefSharp. It's been confirmed by the CefSharp team and is addressed in issue #1819 (https://github.com/cefsharp/CefSharp/issues/1819)
The bug has been apparently fixed, but will not be released until V55.
The solution for now, is to either go back to V51 or to build your own version from source for V55.
We have an intranet web GIS application which I am trying to embed in a WPF application using a WebBrowser control. The application is a proprietary solution from a third party vendor over which I have no control - it works very similar to Google Maps. On my desktop I have Internet Explorer 11 installed, and in Internet Explorer the web GIS works fine. When embedded in a WebBrowser control on a WPF form (.NET 4.5, VS2012) the map loads and will zoom with a roll of the mouse wheel, but will not pan when I try to drag it.
The WPF view is as simple as can be:
<Grid>
<WebBrowser x:Name="TestWebBrowser" />
</Grid>
The code-behind is equally simple:
public MainWindow()
{
InitializeComponent();
this.TestWebBrowser.Navigate("http://myserver/map.aspx");
}
I've tried setting the registry key HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\myapp.exe (and the .vshost.exe variant) to various values without success.
If I change the URL to http://maps.google.com, I can pan the Google map, so I know the WebBrowser isn't fundamentally incapable of allowing drag events in my current configuration, but I can't change the source code of the web application itself.
Any ideas?
If you're running a 32bit app you need to set the registry key in Wow6432Node node.
So your key will look like:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\myapp.exe
I have a WPF application which uses CEF to display web content. My question is, is there a way to debug the Javascript/Web parts inside a WPF application?
You may also use ShowDevTools() extension method (source)
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.ShowDevTools(); // Opens Chrome Developer tools window
Enable remote debugging in your application:
C# (CefSharp)
CefSettings.RemoteDebuggingPort = 8088;
C++
CefSettings settings;
settings.remote_debugging_port = 8088;
then run your app and point your browser to http://localhost:8088/ to access the Chromium developer console (the same you have in Chrome with Ctrl+Shift+j)
While the accepted answer is correct, it doesn't really have enough detail.
I got this working in CefSharp using the WinForms control in a WPF application. (the WinForms control seems to have better performance). The code for remote debugging will probably be very similar for the WPF control though.
var settings = new CefSettings { RemoteDebuggingPort = 8088 };
Cef.Initialize(settings);
WindowsFormsHost.Child = new ChromiumWebBrowser(url);
Then go to http://localhost:8088/ in your browser.
To use 'ShowDevTools()' you will need first verify if the browser is initialized.
An example solution:
//Add an event to check
ChromeBrowser.IsBrowserInitializedChanged += ChromeBrowser_IsBrowserInitializedChanged;
//Declare the event method to be called
private void ChromeBrowser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (e.IsBrowserInitialized)
{
ChromeBrowser.ShowDevTools();
}
}
To open the Chromium Dev-Tools window you can do the following:
CefBrowser.GetBrowser().GetHost().ShowDevTools();
This is similar to Eido95's answer, but it doesn't require the extension methods, which essentially just wrap these method calls.
NOTE: The control needs to be initialized before calling this method can be called. If you're wiring-up and F12-like functionality this shouldn't be a problem. If you're trying to do this when the app is starting you will need to listen for the ChromiumWebBrowser.IsBrowserInitializedChanged event
An alternative can be to launch cef with --enable-chrome-runtime.
You'll have the fully featured debugger (link files on disk and edit them from the debugger)
I am playing around with the WP7 SDK and the Prism for WP7 beta and have come across a problem I can't figure out (or even a workaround for).
First of all, I'm new into WPF/Silverlight/WP7 and Prism, so I could be overlooking something very obvious.
So I have a Shell page that has my region that is used to hold my content pages, and all of this is working great! Now my problem is that I have a settings control that will allow the users to edit the settings of the application (names, locations, etc). Now I can get this page to work with no problems by having a button on one of my controls that will transition the region manager to the control.
However, I would like to use the application bar on the phone to have the button, but I cannot for the life of me figure out how to get access to my model object from within the page that is opened by the Application bar click. I can only do a NavigationService.Navigate() to a settings page, but the PhoneApplicationPage objects in WP7 do not allow injection on the constructors (the constructors must be parameterless) so I cannot pass in the object instance in that way.
So my question is, how can I access (or pass) objects between pages or controls?
Thanks!
In the examples they use this technique to set the data context of a form after it is navigated to from another form:
NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = some_object;
I have a problem in navigation in xBap
I created two pages (Page1 and Page2)
Page1 have one button for navigation to Page 2
<Button Height="23" Width="76" Name="button1" Click="button1_Click">Page2</Button>
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService n = NavigationService.GetNavigationService(sender as Button);
n.Navigate(new Uri("Page2.xaml", UriKind.Relative));
}
in Page2 there is a frame without any source
<Frame Margin="0,90,0,0"/>
After running application, and navigating to page2, the navigation will work normally,
but when I press Go Back in browser, then press button1 again
The browser will show this message
image
Note: in some cases you need to repeat trying
Any help !!
thanks in advance
since your Browser crashes, i suggest this is some bug in one of the following Components:
Browser (IE in this Case)
XBAP Addon/Plugin (yes, there is some kind of plugin which is installed silently within browsers on .NET Framework installation)
I bet, this cannot be solved programmatically... I'd suggest the following:
try to reproduce in different environment (different IE Version, OS etc.)
reinstall .NET Framework and ensure you have the latest, stable final version
do same with Internet Explorer
Firefox has XBAP support as well - try in firefox
If it works in other environments, your users should have no problems with this setup.
Hope this helps,
Best regards
Thomas