WPF in a browser and printing - c#

Can WPF be hosted in a web browser? If so how? (I think it can as I have seen some examples of it.)
While hosted in the web browser what printing support does it have?
What are the drawbacks to using WPF in a browser?
My company is looking for a rich web app platform. They will not choose Silverlight because it ignores any printing needs (at least as far as I understand). Right now a solution from Adobe is in the lead because it supports printing.
Most (if not all) of the apps written for browsers will be used internally by my company (ie we control the computers and browsers). (We want to use browsers for easy of deployment.)

Have you checked out XBAP (Xaml Browser APplications)?
The major drawbacks I am aware of concern security. When some coworkers of mine were developing an XBAP product, they often ran into problems with security, as the XBAP model is pretty strict.
I can't answer about printing, but I'd tend to think that might be a problem with the security considerations.
Hope I was able to help.

If the apps are solely internal and you control the target platform; and the reason for choosing to host your apps in the browser is 'ease of deployment', I would seriously consider writing Full Trust applications in WPF, and deploying them with ClickOnce... Your users would simply have a shortcut on their desktops that would check a server to see if their version of the app is current, and download the newest version if not.
You get all the benefits of the full WPF platform (greater feature-set than Silverlight), and do not need to conform to the Partial-Trust restrictions of XBAP (although you will need to configure the ClickOnce server to allow for Trusted Application Deployment)

No. That's what Silverlight is for right now and yes there are printing limitations. However, printing anything using a web app is not straight forward.

I would suggest Silverlight/Flex solution for web based app and for printing need the best way to do is use iTextSharp library and generate PDF for your reports or printing need, which can be fetched from a URL. PDF is a very standard and adobe reader will always print it right, printing will not be a problem, we went through lot of options and it requires reinventing wheel where else generating PDF through iTextSharp is very easy as creating normal html in javascript way.

Related

how to create a webbroswer in wpf that supports all the sites and scripts and play video?

I have to create a webbroswer in wpf that supports all the sites and scripts and play video , I have created but some site got crashed and not supporting .
Please provide solution.
What you ran into are probably error dialogs caused by JavaScript script errors. WPF WebBrowser control currently doesn't support disabling these dialogs and ignoring the errors. The WebBrowser control is based on Internet Explorer core and will have a hard time dealing with broken JavaScript, webpages will also sometimes report the web browser as old and inform the visitor about it, like FlipKart does.
One solution is to use WindowsFormsHost and host a Windows Forms equivalent - WebBrowser control - in it. The WF WebBrowser offers a property called SupressScriptErrors, which is not implemented by the WPF WebBrowser. That will hide the error dialogs for you, but you will still occasionaly receive a warning from the website saying they don't support the web browser used. That is out of your control unless you want to take a route of hacking the control to send a different User-Agent string and that will only fool broken UA detection, feature detection will still fail for things like HTML5 video, WebRTC and the like. More on this here.
You can also choose to embed Gecko (Firefox rendering engine) or Chromium. see here for more information on embedding alternative rendering cores as an alternative to IE COM wrapper offered by the framework.
Edit: this is also a possible solution, as it would seem. You will have to test it for yourself, though. I expect it to have less overhead than the WindowsFromHost element and although this uses reflection to develop against implementation, not interface, my opinion is it's safe to say the underlaying API in unlikely to change.

Request.Browser.Version returns 7 for IE on Surface Pro?

I'm developing an MVC app.
If I (on my Surface Pro) goes to http://www.whatbrowser.org/ it correctly says IE 10.
But if I go to my MVC app and print out the Request.Browser.Version, it returns 7.
Any idea why? Is Request.Browser.Version broken?
Thanks
Some of this is touched on in Detect Internet explorer browser version problems.
Last I knew Request.Browser uses the *.browser files that come with the installs of ASP.NET, and easily get out of date. Microsoft releases updates to them every so often, but not often enough. Currently there are some issues with webform pages breaking on IE10 without updated browser files.
Like the comments have said, browser detection is very broken. If you need to detect the browser, at the very least shy away from using the user agent string, and seriously consider why you need to know exactly what browser is used.
Request.Browser.Version doesn't always return the 'correct' browser version for IE because of many factors including compatibility view, meta tags etc.
You would be better off detecting browser capabilities instead. Further reading here: http://msdn.microsoft.com/library/3yekbd5b
As a personal preference, it would be best to detect the OS instead of the browser. Most of the common HTML5/CSS3 features are supported in IE9 and above and IE9 requires Windows Vista and up. The best way to do this using the User Agent is by checking the Trident. If there is compatibility view enabled via the browser or by using meta tags by the app itself, the wrong 'version' is returned but the Trident remains correct.
PS. This isn't fool proof but this would work most of the time.
Further reading about Trident here: http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#PltToken

HTML/CSS/JS in desktop applications

I've read about XSS vulnerability in desktop applications like Skype and ICQ.
I wonder why they choose to use html in this kind of applications that can also be written without any html. Is there a simple reason?
Does someone know if Skype uses html on pages like "Skype Home" only or is the whole GUI written in html?
I'm asking because I'm writing a web application that runs within the browser and will be ported to mobile and desktop platforms once finished. You can compare it to instant messengers but it's something different in fact.
I thought about using PhoneGap to simply "copy" the project to mobile platforms and using system functions via the PhoneGap API. But I think it may be slow and/or not good-looking. Also it wouldn't look native, the question then is whether too use our own html GUI on all platforms (so it looks the same everywhere) or to adapt the design concepts of each platform (using native controls in native languages or e.g. Titanium (which is unfortunately too expensive)).
But I never thought about using HTML in desktop applications. How do you embed that anyway? I'm using C#. Using WebBrowser form element or using some kind of web browser rendering engine?
To answer the initial question (in your 1st paragraph):
I assume they chose to wrote it using HTML as a way to make it cross-platform more easily.
You can't make desktop applications using purely HTML/CSS/JS and have them looking native. However you can use Sencha Touch to make your Phonegap applications look native (to an extent).
Mozilla Prism was written with this idea in mind: http://prism.mozillalabs.com/
Have you tried Appcelerator Titanium Desktop/Mobile. They have a similar idea there - http://www.appcelerator.com/
Thanks.
You can use the WebBrowser control to basically host an internet explorer session in your windows application. This is platform specific, but there is a commercial version which is available for some smartphones: http://en.wikipedia.org/wiki/Mono_(software)#MonoTouch_and_Mono_for_Android.
You can make an HTML5 application which will give you a lot of the benefits of a fat client while maximizing portability with smartphones. You can still have the user save the application to the desktop: http://miniapps.co.uk/installation/. But, that's clunky and, like the desbest said, it will run in a web browser. If you want to maximize the customization, then it looks like PhoneGap is an choice worth taking a look at to me as well.

Can an exe compiled from C# be integrated into a website?

I'm a beginner in programming. I've just made a program called "Guessing Game". And it seems to work fine. Can I integrate it into a website? The CMS that I'm using is Mambo.
===
additional info's
Thanks for all your suggestions.
I still don't have any background about Silverlight, WPF and Java Script which I think sounds good. I'm using Windows and I programmed my "Guessing Game" from Microsoft Visual Studio 2008 and it's using Window application forms.
Yes I guess, for the moment I let it be and start to learn Silverlight or Java Script so that I can integrate it on my website:-)
Thanks for all your input guys:-)
Cheers
A standalone executable cannot be directly integrated into a website. You have a few choices though:
Allow your users to download the executable and run it locally for themselves
Rewrite your program in JavaScript to have it run directly inside of an HTML page, though this could obviously involve a fair amount of reworking
Use Microsoft's Silverlight technology, which allows you to code in C# and produce a web-based frontend similar to Adobe Flash. Your program logic should remain the same and you should only have to change the UI code. In fact if you're already using WPF for the front end, the transition will be even easier.
There are several questions that you still need to answer.
What is your server running? If its not Windows, your exe will not run at all unless it is compatible with Mono or a similar framework for your server's operating system.
How does your "Guessing game" interact with the user? If it is through a WinForms GUI, it will you will not be able to use that GUI on the web. If your game is a WPF application your easiest route may be to port it to Silverlight and serve it up on a web page.
It is typically not trivial to make a regular windows application run in a web environment since on on the web you are really running in the browser, not on Windows.
Yes - in general, when you're talking about software, anything is possible. The question is, how difficult will it be?
To understand that, you have to give us more details about "Guessing Game" including how it is designed, what it's interfaces are, how readily extensible it is, and how prepared you are to change or extend it.
For example, if it is a Windows Forms GUI app, then it will be diifficult to integrate into a web app. If it is a console app, then it will be a little easier. If you can modify it to run as a Windows Service, then a little easier. If you can modify it to accept input from the network (as opposed to getting input solely from the keyboard + mouse), still easier.
You may be able to use reflection to load your assembly into the web application, but most likely, the answer is no.
Your best solution is probably to re-write the game in javascript.
The short answer to your question is now. I'm presuming that since you're running Mambo you're web environment is a LAMP stack. However, you're "Guessing Game" is most likely a Windows application from the sound of it. For a beginner in programming, there is no integration path you're going to be able to take that will allow you to have your game running on your website.
However, here are avenues you can take, which will require a significant amount of time to learn. I'm not saying you shouldn't take time to learn, by all means you should! I'm simply trying to illustrate the fact that this is not something that is going to be doable in a couple of hours.
Silverlight - allows you to run C# code with a WPF like interface on your client's browser and can integrate with your web site through javascript.
Let your client download it from your website and run it off of their PC. This would actually be fairly trivial and would be your quickest option, but it sounds like it's not the kind of integration you were looking for.

Is there any better web browser control in C# (.NET)?

I need JavaScript working almost perfectly in my application that should be able to access web content and let user take a control of it. However, webbrowser component pops new windows in separate instance / application of Internet Explorer and dotBrowser doesn't work with JavaScript properly.
Please, give me some advice - I'd even take some working example and enhance it with function I need it for.
Give a look to GeckoFX, is on open-source component for embedding the Mozilla Gecko (Firefox) in .NET applications.
I could be mistaken, but I believe new windows can be controlled (or at least suppressed) using the Web Browser control in .NET. Have a look at the NewWindow event.
I have had experience embedding both WebKit (Apple Core, used in Chrome) and XULRunner (Gecko) cores in .NET winforms applications. Let me give you some advice:
GeckoFX is your best bet. It is licensed under MPL and it works pretty much out of the box.
Follow the instructions carefully and pull the exact XUL version that is indicated. I would say it works better than the WebBrowser control. There is some talk of a significant delay when loading XUL for the first time but I've found it to be negligible. Branding and the like is fully customizable via external files.
WebKit is embeddable with SwiftDotNet. If all you need is solid javascript performance then this may be an option. If you need to be able to download files, then you have some work cut out for you.
Your downside with both routes is a nasty ~7-8mb overhead, even with compression (although I was able to get 6.5mb with lz compression in NSIS). If you are not creating distributable consumer-facing software then this may not be a problem for you.

Categories