How to display HTML in Silverlight application? - silverlight

I would need to display some basic HTML (just some paragraphs, unordered lists and hyperlinks) in my Silverlight application. How would I go about that?
Which control to use?

Try this link for starters: http://www.wintellect.com/CS/blogs/jprosise/archive/2009/12/22/silverlight-4-s-new-html-hosting-support.aspx
Here is the relevant part:
Another of the new capabilities that Silverlight 4 brings to the
platform is the ability to host HTML content inside a Silverlight
control. This support isn't limited to static HTML content; the
content can be interactive and can include script. It can even be
Flash content or content that includes other Silverlight controls.
To host HTML content in Silverlight, you can use either a WebBrowser
control or an HtmlBrush. One way to display HTML content is to fire up
a WebBrowser control and point it to a URL:
<WebBrowser x:Name="WebBrowserControl" Source="http://www.bing.com" />
Another way to do it is to call NavigateToString and pass a string of
content to the WebBrowser control:
WebBrowserControl.NavigateToString("<h1>Hello, Silverlight</h1>");
HTML hosting is not available to in-browser apps (it applies to
out-of-browser applications only), and if an OOB lacks elevated
permissions, it can only display content that comes from the same
domain as the Silverlight application. However, you can use a little
trick to display cross-domain content in OOBs that run without
elevated permissions—simply pass an IFRAME targeting the remote
content to NavigateToString:
WebBrowserControl.NavigateToString("<iframe src=\"http://www.bing.com\" style=\"width: 100%; height: 100%\"></iframe>");
You can render HTML content with HtmlBrush, too. The following XAML
snippet paints a Rectangle with content retrieved from Bing:
<WebBrowser x:Name="WebBrowserControl" Source="http://www.bing.com" />
<Rectangle>
<Rectangle.Fill>
<HtmlBrush SourceName="WebBrowserControl" />
</Rectangle.Fill>
</Rectangle>
One difference between WebBrowser and HtmlBrush is that the former
displays "live" content, while the latter does not. Another difference
is that HtmlBrush can have transforms applied to it, while WebBrowser
cannot. For snazzy visual effects involving HTML content like the HTML
puzzle demoed at the PDC, you'll probably find yourself using
HtmlBrush. To display live, interactive content, you'll find
WebBrowser more useful instead.
One of the really cool things about the WebBrowser control is that you
can use its InvokeScript method to call JavaScript functions in
content hosted by the control. Conversely, JavaScript hosted inside a
WebBrowser control can use window.external.Notify to raise
ScriptNotify events that can be handled in C#.

You could use HtmlBrush or webbrowser control.

Related

How to use .js and .css file in SilverLight application

I am using a customized alert message for my whole application which generates from a .js file and a .css file. I have also used silverlight in my application and shows MessageBox from silverlight with its default design. Now i want to customized that MessageBox in silverlight.
So, can anyone plz help me to know how to add js and css file to silverLight application and how to use it
You can't change the built-in MessageBox style as easily as simply creating your own modal window. There are lots of custom messageboxes about and many have source code.
e.g.
Creating a reusable MessageBox dialog.
Silverlight Modal Dialog With Custom User Controls
Custom MessageBox Control for Silverlight 3
Note: these are all Silverlight solutions, so you are authoring in XAML and with style, not using JS and CSS.
It is also possible to call JS functions on the page from within Silverlight if you think that will be easier for your solution.

Embedding of Webbrowser in WPF Form with Address bar + Buttons

I wouldlike to embed a webbrowser in a WPF application. The browser should look like a normal browser, with address bar, back and forward button and status bar. Is there a way how that could easily written in XAML, with a direct databinding of the address to a textbox, with a direct routing of events from the buttons to the webbrowser object, and the enabling back?
Why not?
Here and here are uploaded some screenshots from our application which has WebModule inside and is able to work like browser.
In our implementation we used Windows Forms WebBrowser control as browser engine and MVVM as communication pattern. Model has navigation commands (forward, back, ...) that raise proper events. View is handling this events and delegate requested actions to inner WebBrowser component. Additionally view is handling WebBrowser's events (NewWindow, DocumentCompleted, Navigating, Navigated) and setting up model's state.
Model and view together contain about 500 lines of code (I don't think it's very much, do you?).
Of course, I should mention, that due to using IE engine this browser could have some problems on complicated web-sites.
P.S. We didn't use System.Windows.Controls.WebBrowser because it does not provide access to NewWindow event.
P.P.S. I've posted this answer from browser in our WPF application. Good luck!

How to embed IE (created using Watin) inside a WPF application [duplicate]

Can I embeded IE in my wpf application and interact with it firing events?
e.g. can I fill a form and press submit button programmatically?
Below is the link to the web browser control for WPF, this control was not part of the initial release of WPF, and was added in 3.5 SP1. As long as you are targeting 3.5 SP1 you can use this control and interact with the content in it. I have a WPF application that does use this control and we do a lot of JavaScript interactivity with the content from the browser by drawing on a WPF canvas and sending that information to the content API of the web browser control.
If you need an example I can look up some code samples from the application and send them your way.

Can I embeded IE in my wpf application and interact with it firing events

Can I embeded IE in my wpf application and interact with it firing events?
e.g. can I fill a form and press submit button programmatically?
Below is the link to the web browser control for WPF, this control was not part of the initial release of WPF, and was added in 3.5 SP1. As long as you are targeting 3.5 SP1 you can use this control and interact with the content in it. I have a WPF application that does use this control and we do a lot of JavaScript interactivity with the content from the browser by drawing on a WPF canvas and sending that information to the content API of the web browser control.
If you need an example I can look up some code samples from the application and send them your way.

opening a silverlight childWindow overlay on the viewport of the browser

I would like place a silverlight contol on an HTML page --- something about the size of a typical calendar control. However when the user selects a day on the control a bigger canvas opens up on top of the containing page --- something like a modal dialog box that you might find with the AJAX.
I'm wondering if this is even possible with Silverlight, or is the silverlight content limited in size to the DIV element on the host page?
UPDATE: after doing some poking around, I think the answer will involve using the ChildWindow control introduced with Silverlight 3. However I'm still at a loss how to have the ChildWindow display ontop of the existing content
I know one way, you will need javascript event on the page itself to expand a silverlight object to fit the whole page then build you silverlight event accordingly.

Resources