ASCIIEncoding In Windows Phone 7

It is easy to implement yourself, Unicode never messed with the ASCII codes: public static byte[] StringToAscii(string s) { byte[] retval = new byte[s.Length]; for (int ix = 0; ix < s.Length; ++ix) { char ch = s[ix]; if (ch <= 0x7f) retval[ix] = (byte)ch; else retval[ix] = (byte)’?’; } return retval; }

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

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

How can I data bind a list of strings to a ListBox in WPF/WP7?

If simply put that your ItemsSource is bound like this: YourListBox.ItemsSource = new List<String> { “One”, “Two”, “Three” }; Your XAML should look like: <ListBox Margin=”20″ Name=”YourListBox”> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=”Horizontal”> <TextBlock Text=”{Binding}” /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Update: This is a solution when using a DataContext. Following code is the viewmodel you will be … Read more