Silverlight webpage preview control - silverlight

I'm making a silverlight app that when the user does a mouse-over some tab bars, he/she will see a preview of the page it will link to. The reason for this preview is that just having a visual miniature of the page is often enough to make the desicion for the user. How do I in Silverlight make a control that simply displays a webpage, preferably scaled down?
Cheers
Nik

As you are probably aware, there are some issues relating to crossing domain boundaries in Silverlight. Issues that have been discussed on stack overflow for example.
This is relevant because generally you can't request web resources in other domains which you'd need to do here.
One way I've seen to get around this is to use a web service that doesn't have the same limitation. So you can create a web service that exposes a byte[] of the image and have the web service do the calls to retrieve the image and send it back to Silverlight.
Once you've got the image byte[] you can read that in an asynchronous call, and set the image source like this.
BitmapImage thumb;
using (MemoryStream stream = new MemoryStream(imgArray))
{
thumb = new BitmapImage();
thumb.SetSource(stream);
}
The other issue is how to generate the thumbnail, for that you can google, there are some projects that show you how and some public web services that do it for you. Amazon's is one such example.

Related

Passing text data from silverlight to plain page

I have written app in silverlight which reads qr codes from webcam. I need to pass data (paste pure text) from silverlight to active field on page which contains silverlight, but not inside silverlight. Is there any way to do this? There is also restriction that user interacts by showing qrcode to webcam not actually clicking anything (problem with clipboard and silverlight - which can be used only in certian situations).
Any suggestions or guidelines is welcome.
You can interact with the page hosting the Silverlight object. From Silverlight:
HtmlPage.Window.Eval(string.Format("processQrCode('{0}')", textData)
There should be javascript in the page:
function processQrCode(data) {
// Do something with the data here
}

Sending info and other questions for windows phone 7

I'm rather noob for WP7 developing, and I've got some questions for my new app:
Is it possible to send some information from time to time to my server while the app is hidden (running at background) ? If it is possible, won't it be rejected by Microsoft (my app will say to user about this, of course) ? I want to watch user's location and send it to server, to be honest:)
Is it possible to draw overlays for MapViews? I know, that for iOS apps it is possible
Is it a bad practice for Silverlight apps to put my own images under all buttons and controls on page, and to redefine controls' style? I don't want to support native themes
Thanks!
1.Yes. Background Agent can run every 30 minutes and send location to a server
2.Yes. Microsoft.Maps.MapControl has all you need. For example draw lines with MapPolyline class:
MapPolyline polyline = new MapPolyline();
polyline.Locations = new LocationCollection();
map.Children.Add(polyline);
3.You can do anything. Buttons can be Metro style with images also. But try to keep applications look in consistency with a system

Loading Images for Silverlight app from server without ssl

I have an Silverlight application that uses ssl to communicate with the site-of-origin. The application loads a number of images from a separate server (running apache under port 81 without ssl). The images are regular png's. The images from the Apache machine are not loaded properly, i.e. the image control remains blank. When I post the same image on my app server (i.e. site-of-origin), and modify the link accordingly, the images are displayed properly. This link on MSDN says that images are media are excluded from access-restriction policies.
Would appreciate any suggestions.
I hope you are deploying your Silverlight application to a web server and not running it using the Visual Studio development server. I had a similar problem with images when I was using the built in development web server. You can find about my experience here.
It might help if you subscribe to ImageFailed event and post the stacktrace.
You are running into cross-scheme access restrictions in silverlight, see table at the bottom of http://msdn.microsoft.com/en-us/library/cc189008(v=vs.95).aspx
One possible solution is to load image using WebClient and call SetSource on image element. That is what we do in our app. In fact we wraped it into custom image control that hides all annoying details.

Showing the result of a WebClient-postback in an Browser Window from Silverlight 4

I want to show the result of a WebClient-Postback in an new Browser-Popup-Window. As the "Navigate" and "Popup" methods of HtmlPage only support Get-requests, I issued an POST-request to an REST-Service via WebClient. But now I want to show the result (e.g. application/ms-excel or application/pdf) in an new Browser-Window.
Therefore, can I open an new BrowserWindow and set its contents as well as some corresponding http-headers with on-board means of Silverlight 4? Or even better, is an easier way to trigger the browser to do the POST-request to the service?
Best Regards
I tried going this route but the WebBrowser control is not opened to the developer. What I did as a temporary workaround was to open my webpage http://www.xyz.com/default.aspx inside the WebControl and let the page drive the rest.
Mike Taulty had an example for somthing like this, how you can use javascript to communicate back to the silverlight app through InvokeScript:
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-html-hosting-in-the-webbrowser-control.aspx
I hope it helps!

Cross-site images in Silverlight

Is it possible to load in an image from another domain using JavaScript, and then pass the image to a Silverlight control on my page?
The only workaround I'm familiar with for this, since it's a security issue, is to set up a web service on a server you have control over, request the image from this web service from your Silverlight application, then have the service grab the image from the other server and return it to the client.
Loading cross-domain images should not be an issue in Silverlight, at least if you are using the normal Image control. I just tested this with a really simple application containing only an Image control with the Source property set to an image from google images.
Are you loading your images in some funky way with the WebClient? Cross-scheme and cross-zone access is restricted for the Image class, so you would not be able to load an image (on any domain) over SSL if you loaded your XAP over regular HTTP.
The MSDN page on Silverlight URL Access Restrictions gives you a good overview of what you can and cannot do with Image, MediaElement, WebClient, and streaming video.

Resources