How to POST request using RestSharp

My RestSharp POST method: var client = new RestClient(ServiceUrl); var request = new RestRequest(“/resource/”, Method.POST); // Json to post. string jsonToSend = JsonHelper.ToJson(json); request.AddParameter(“application/json; charset=utf-8”, jsonToSend, ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; try { client.ExecuteAsync(request, response => { if (response.StatusCode == HttpStatusCode.OK) { // OK } else { // NOK } }); } catch (Exception error) { … Read more

How to programmatically set selected Panorama item in WP7

I’m not sure if you can programmatically force an animation to another PanoramaItem, but you can change the Panorama.DefaultItem. So you might have 3 PanoramaItem‘s and on the OnNavigatedTo() handler, change the default item via: panoramaControl.DefaultItem = panoramaControl.Items[indexToSet]; This should help when you recover from a tombstone.

Conversion of BitmapImage to Byte array

Well I can make the code you’ve got considerably simpler: public static byte[] ConvertToBytes(this BitmapImage bitmapImage) { using (MemoryStream ms = new MemoryStream()) { WriteableBitmap btmMap = new WriteableBitmap (bitmapImage.PixelWidth, bitmapImage.PixelHeight); // write an image into the stream Extensions.SaveJpeg(btmMap, ms, bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100); return ms.ToArray(); } } … but that probably won’t solve the … Read more

Passing a complex object to a page while navigating in a WP7 Silverlight application

This is an extremely complex problem, and there is no simple solution here. There is no magic API that would just work for any app to solve this problem. The core problem with passing navigation data is Tombstoning. The only piece of data that is tombstoned by default is the Navigation URI. so if you’re … Read more

WebClient does not support concurrent I/O operations

The WebClient only supports a single operations, it cannot download multiple files. You haven’t shown your code, but my guess is that you are somehow firing a new request before the old is completed. My bet is that WebClient.IsBusy is true when you attempt to perform another fetch. See the following thread: wb.DownloadFileAsync throw “WebClient … Read more

Use local images in Webbrowser control

You will need to store your images in the Isolated Storage and then display the images from there. I have put together a sample that you can download from the following location :- www.smartmobiledevice.co.uk/projects/webbrowserimagesample.zip This is based on the MSDN article How to: Display Static Web Content Using the WebBrowser Control for Windows Phone.

Deserializing JSON array into strongly typed .NET object

Afer looking at the source, for WP7 Hammock doesn’t actually use Json.Net for JSON parsing. Instead it uses it’s own parser which doesn’t cope with custom types very well. If using Json.Net directly it is possible to deserialize to a strongly typed collection inside a wrapper object. var response = @” { “”data””: [ { … Read more

Add custom header in HttpWebRequest

You use the Headers property with a string index: request.Headers[“X-My-Custom-Header”] = “the-value”; According to MSDN, this has been available since: Universal Windows Platform 4.5 .NET Framework 1.1 Portable Class Library Silverlight 2.0 Windows Phone Silverlight 7.0 Windows Phone 8.1 https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.headers(v=vs.110).aspx

tech