HttpUtility.UrlEncode in Windows Phone 7?

Silverlight has the Uri.EscapeUriString and Uri.EscapeDataString which can be used to URL-encode portions of a URI such as query strings and path components and such. Even in the desktop framework, you should never take a dependency on System.Web.dll just for HttpUtility, although many developers still do it. This is bad for 3 reasons. The assembly … Read more

What is the difference between Property and Dependency Property

Dependency properties and standard properties are quite different. The key features delivered by dependency properties are support for binding and animation. If you want to assign a value to a property using a Binding or template binding that property needs to be a dependency property. When animating a property the a dependency property can track … Read more

Silverlight: image to byte[]

(the bits per pixel method you are missing just details how the color information is stored per pixel) As anthony suggested, a WriteableBitmap would be the easiest way – check out http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html for a method to get an argb byte array out : public static byte[] ToByteArray(this WriteableBitmap bmp) { // Init buffer int w … Read more

Is there any difference in x:name and name for controls in xaml file?

In Brief Yes there is a difference. The bottom line is that x:Name can be used on object elements that do not have Name properties of their own. A longer explanation You can only use Name on an element that represents an object that actually does have a Name property. For example anything that derives … Read more

Measuring the length of string containing wide characters

As documented: The Length property returns the number of Char objects in this instance, not the number of Unicode characters. The reason is that a Unicode character might be represented by more than one Char. Use the System.Globalization.StringInfo class to work with each Unicode character instead of each Char. Getting length: new System.Globalization.StringInfo(“友𠂇又”).LengthInTextElements Getting each … Read more

Building Dynamic LINQ Queries based on Combobox Value

Assuming: public class Person { public string LastName { get; set; } } IQueryable<Person> collection; your query: var query = from p in collection where p.LastName == textBox.Text select p; means the same as: var query = collection.Where(p => p.LastName == textBox.Text); which the compiler translates from an extension method to: var query = Queryable.Where(collection, … Read more

How to zoom in and zoom out Images in WP7?

Perhaps the most expedient approach would be to include the Silverlight for Windows Phone Toolkit. This contains a GestureService that will help with pinch and rotate touch gestures. You could apply it to an image like this:- <Image Source=”someSourceUrl” RenderTransformOrigin=”0.5, 0.5″ CacheMode=”BitmapCache”> <Image.RenderTransform> <CompositeTransform x:Name=”transform” /> </Image.RenderTransform> <toolkit:GestureService.GestureListener> <toolkit:GestureListener PinchStarted=”OnPinchStarted” PinchDelta=”OnPinchDelta” /> </toolkit:GestureService.GestureListener> </Image> Then … Read more

Get current Windows user name within Silverlight

You can manage to get by this way. 1) Create asp.net web service application. 2) Implement web service and method to call from silverlight applicaton. [WebMethod] public string GetClientUserName() { return System.Web.HttpContext.Current.User.Identity.Name.ToString(); } 3) Deploy this web service application on web server. Don’t allow anonymous user to access this. 4) Add this service to Silverlight … Read more