Getting Started with Silverlight Development on Windows Phone
Features Supported in Silverlight for Windows Phone
Silverlight for Windows Phone is based on Silverlight 3. Additional Silverlight-based features, which are not present in Silverlight 3 but are specific to Windows Phone, are also supported. This topic provides an overview of supported features and links to additional information.
The following Silverlight 3 features are supported on Windows Phone in the current CTP.
Application development in C# is supported. Visual Basic is not supported yet.
The following list includes features supported by the .NET Compact Framework in Silverlight.
The following additional features are supported in Silverlight on Windows Phone, but are not supported in Silverlight 3.
-
Gesture-aware controls
-
Manipulation events
-
Software input panel (SIP) support on the TextBox control
-
Silverlight extensions that support features specific to Windows Phone. For additional information, see the Class Library Reference for Windows Phone.
In some cases, supported features might include behavior differences from the corresponding feature on Windows. For feature implementation differences, see Differences Between Silverlight on Windows and Windows Phone.
The following features are not supported on Windows Phone
This is not a complete list. For detailed information about unsupported types and members, see Class Library Support on Windows Phone.
-
New Silverlight 4 features described in What's New in Silverlight 4
-
Browser host
-
Dynamic language runtime (DLR)
-
Expression trees
-
HTML DOM bridge
-
JavaScript programmability
-
Reflection.Emit
-
Silverlight plug-in object reference
-
Sockets
-
Silverlight SDK features, including the following:
-
Windows Presentation Foundation (WPF) controls
-
WCF Data Services (formerly ADO.NET)
-
Duplex communication over HTTP
-
JSON serialization
-
RSS and Atom feeds (syndication)
Differences between Silverlight 3 on Windows and the Windows Phone
This topic describes feature implementation differences between Silverlight 3 on Windows and Silverlight on Windows Phone.
The following topics provide additional information about Silverlight on Windows Phone.
Controls
Supported controls are updated with the Windows Phone 7 Series UI theme.
For a list of Silverlight controls supported in the Windows Phone 7 Series, see the Controls topic in Windows Phone Developer documentation.
Media
For information about media implementation differences between Silverlight on Windows and Silverlight on Windows Phone, see Media on Windows Phone.
Deep Zoom
Silverlight for Windows Phone always uses hardware acceleration on a MultiScaleImage image, if possible. As a result, any change you make to the CacheMode property of MultiScaleImage is ignored.
Delegates
Asynchronous delegate calls, specifically the BeginInvoke and EndInvoke methods, are not supported in the .NET Compact Framework.
If you attempt to invoke delegates asynchronously, the application throws TargetInvocationException instead of NotSupportedException.
Finalizers
Constrained execution regions (CERs) are not supported in Silverlight for Windows Phone.
Fonts
Font support is controlled by the fonts that are already present in ROM on the device. No fonts are installed with Silverlight.
Web-safe fonts are recommended, such as Verdana and the Segoe WP fonts.
Visual Studio 2010 Express for Windows Phone CTP includes filters that show supported fonts on Windows Phone 7 Series.
If the fonts that you want are not present on the target device, we recommend that you deploy them with the application. We recommend that you use the TrueType font format for fonts you need in the application.
Embedded fonts must be added to the DLL or XAP as embedded resources to be supported by the runtime for managed-code scenarios.
Graphics
Graphics, animations, and effects such as Blur and DropShadow are supported. In Silverlight for Windows Phone, effects are hardware-enabled, so you must set the CacheMode property of the UIElement to BitmapCache.
Custom pixel shaders are not supported, so the PixelShader type is not supported.
For additional information about graphics and animation in Silverlight, see the following topics.
Hosting
Silverlight applications on Windows Phone are hosted on the client device and do not run inside of a browser. Silverlight features that are based on a browser host are not supported. These features include the HTML DOM bridge, JavaScript programmability, and the Silverlight plug-in object reference.
Input
Controls that are supported on Windows Phone are gesture-aware, and support gestures such as tap, pan, and flick.
You can handle simple gestures such as tap, double-tap, and tap-and-hold by using mouse events.
-
Use MouseLeftButtonUp for tap gestures.
-
To handle double-tap, check whether two mouse up and down events occur within a TimeSpan. If the MouseMove event does not occur between the first up and second down event, a double-tap occurred.
-
To handle tap-and-hold, start a TimeSpan timer when the MouseLeftButtonDown event occurs, and store the user's touch location. In the MouseMove event, check whether the user has moved the touch location more than a few pixels. If the location has moved, cancel the timer. If the MouseLeftButtonUp event occurs before the timer expires, you also cancel the timer. If the timer expires before it is cancelled, a hold event occurred.
You can also use manipulation events to respond to touch input. Manipulation events support multitouch input and can be used to move and scale objects derived from UIElement. For additional information, see How to: Handle Manipulation Events.
Isolated Storage
Isolated storage allows applications to store data in a virtual file system. The data is completely isolated from other system components. This prevents unauthorized access and data corruption by components other than the application that is storing the data.
Isolated storage on Windows Phone does not enforce quotas to restrict the size of isolated storage for Silverlight-based applications. The default quota size of 1 MB does not apply.
The application size limit is 2 GB on Windows Phone.
Implementation differences between Silverlight on Windows Phone and Silverlight on Windows include the following:
-
Isolated storage on Windows Phone does not include the concept of a site; therefore, GetUserStoreForSite is not supported.
-
IncreaseQuotaTo throws an exception.
-
In the IsolatedStorageFileStream class constructor, FileShare.Delete and FileShare.Inheritable are not supported because of a platform limitation.
-
The default quota size returned to an application is MAXLONG.
For information about isolated storage in Silverlight, see the following topics:
LINQ
LINQ query providers for custom data sources are not supported in Silverlight for Windows Phone.
Localization
Some of the types and members that support localization behave differently on Silverlight for Windows Phone, as follows:
-
A custom culture returns standard formatting when custom formatting is expected. For example, 31/08/2006 12:30:15 Afternoon! returns as 8/31/06 12:30:15 PM.
-
You cannot use a neutral culture in formatting and parsing; therefore you cannot set a neutral culture as the thread's current culture.
-
DateTimeFormatInfo.GetEra returns -1 for the fr-FR culture.
-
DateTimeFormatInfo.GetEraName method returns incorrect values in some cases. For example, the fr-FR localization string DC is returned when A.D is expected.
-
DateTime.ToString does not return the correct string for Russian dates. For example, 15.Июнь.2000 is returned instead of 15.июня.2000.
-
Double.ToString() does not return the correct string containing comma delimiters between group digits when a custom format is used.
Multitouch and Manipulation Events
To enable multitouch and manipulation events, Silverlight for Windows Phone supports types, members, and events that are not present in Silverlight 3. For additional information, see How to: Handle Manipulation Events.
Navigation
Silverlight for Windows Phone provides a different page navigation model than Silverlight on Windows. The Frame and Page classes are not supported. For additional information, see the Frame and Page Navigation topic in Windows Phone Development.
Networking
Support for networking features in Silverlight for Windows Phone includes Windows Communication Foundation (WCF), HttpWebRequest, and WebClient.
Custom bindings and sockets are not supported.
Because ChannelFactory<(Of <(TChannel>)>) is not supported, you cannot generate proxies dynamically. You must use slsvcutil.exe on the command line to generate compile-time proxies.
The Add Service Reference option in Visual Studio also generates proxies you can include at compilation. This option is not supported in Windows Phone projects in the Community Technology Preview.
The following XmlSerializerFormatAttribute properties are not supported:
Some networking features in Silverlight are not supported. For additional information, see Features Supported in Silverlight for Windows Phone.
Some networking types and members are not supported. For additional information, see Class Library Support on Windows Phone.
Performance
Devices have less processing power, storage, and memory than desktop computers. They also have a limited battery life. You must design applications with these constraints in mind, especially for applications that use animation and media. Some devices might not perform well when the application uses multiple Storyboard objects or manipulates a large number of XAML elements.
To optimize XAML code when applying multiple transformations, Silverlight for Windows Phone supports CompositeTransform.
Reflection
Reflection implementation differences between Silverlight on Windows and Windows Phone are as follows:
-
Some types and members are not supported in Silverlight for Windows Phone. For a list of unsupported methods, see Class Library Support on Windows Phone.
-
Open generics are not supported in Silverlight for Windows Phone.
-
In Silverlight for Windows Phone, the ignoreCase parameter is not supported on GetType. You must use case-sensitive type names.
-
Behavior and functional differences exist between the binder implementation in Silverlight 3 and that in the .NET Compact Framework.
-
The equality (==) operator for two equal MethodInfo objects does not return true in Silverlight for Windows Phone.
-
The System.Reflection.Emit namespace is not supported in Silverlight for Windows Phone.
-
GetNestedTypes returns all nested types irrespective of the BindingFlags value.
-
AssemblyName.GetPublicKeyToken returns null instead of byte[0] for a byte[0] PKT or for an assembly name containing PublicKeyToken=null.
-
For the declaringType parameter, MethodBase.GetMethodFromHandle(MethodHandle, TypeHandle) uses RuntimeMethodHandle instead of RuntimeTypeHandle.
-
WaitHandle.WaitAll is not supported in .NET Compact Framework.
-
AssemblyName().ToString() and Assembly.FullName return System.Reflection.AssemblyName when the default constructor was used to instantiate the AssemblyName object.
-
In Silverlight for Windows Phone, ParameterInfo.DefaultValue returns null.
-
Type.GetMember method does not return any public members with the specified name if the name string is a regular expression.
-
Type.GetMethods and Type.GetMembers methods do not return the same object instance.
-
AssemblyName.FullName does not return PublicKeyToken information by default. .NET Compact Framework only provides the assembly name. You must use individual methods to compare the culture, version, and PKT information.
-
FieldInfo.ToString() returns System.Boolean[] instead of Boolean[] when it points to a bool.
-
Type.GetMethod(String, Type[]) returns a null MethodInfo value for the Set(Int32, System.String) method while desktop returns a MethodInfo value, which is not necessarily null.
-
The return value for Type.AssemblyQualifiedName is not the same between Silverlight for Windows Phone and . For example, the return value for AssemblyQualifiedName on Silverlight for Windows Phone might look like this: MyType, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089. In , the equivalent return value might look like this: MyType, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=B17A5C561934E089.
Regular Expressions
In Silverlight for Windows Phone, the CacheSize property always returns zero because the Regex class implementation does not support caching.
Runtime
Silverlight on Windows Phone 7 Series runs on the .NET Compact Framework.
Security
The following differences apply to X509 certificates:
SIP
To enable you to set the software input panel (SIP) on a TextBox control, Silverlight for Windows supports several types and members that are not present in Silverlight 3. For more information, see How to: Specify the SIP Layout in a TextBox.
Silverlight Extensions for Windows Phone
For additional features that are specific to Windows Phone development, see the Class Library Reference for Windows Phone. These features are included in the Windows Phone Developer Tools.
Text Encoding
The Encoding.Unicode encoder is named System.Text.UnicodeEncoding+UnicodeEncoder on Windows Phone.
The Encoding.Unicode decoder is named System.Text.UnicodeEncoding+UnicodeDecoder on Windows Phone.
Threads
Unlike Silverlight 3, Silverlight for Windows Phone splits animation work on two different threads for better performance on devices.
ThreadStaticAttribute is not used by the .NET Compact Framework.
URIs
In Silverlight for Windows Phone, the HttpUtility class is in the System.Net namespace. On Windows, this class is in the System.Windows.Browser namespace, which is an unsupported namespace on Windows Phone.
Uri.LocalPath does not convert the forward slash (/) to a backslash (\). This is because file-based URIs (URIs of the form file://) are not allowed. Paths returned are relative paths.
The OriginalString property for a URI instance trims any leading space before the scheme in the URL.
Visual Basic
On the .NET Compact Framework, LINQ query syntax in Visual Basic does not support the Select clause where the operator is optional. That is, if the Select clause does not include parameters that change the default result of the query, you must remove the Select clause.
Visual Basic is not supported in this release.
The Visual Basic runtime cannot test equality with object references to XNamespace and String.
XAML Transformations
To optimize XAML when you are applying multiple transformations, Silverlight for Windows Phone supports CompositeTransform.
XML
Parse is not supported in Silverlight for Windows Phone because the .NET Compact Framework does not support document type definitions (DTDs). The application throws a NotSupportedException when it encounters a DTD string in XML. To parse DTDs, an application must either implement this feature or use XML schemas.
Commonly used DTDs are provided through XmlPreloadedResolver. However, this type is present in the Silverlight 3 SDK, which is not supported in the Community Technology Preview.
The following differences also apply to Silverlight for Windows Phone:
-
The serialized output of an XmlSerializer object of type XmlQualifiedName is not well-formed.
-
Wrapping a custom reader is allowed in .NET Compact Framework. That is, you can create a custom reader with your own implementations of the required functions, and then pass the custom reader as input to XmlReader..::.Create(XmlReader, XmlReaderSettings).
Other Differences
Additional implementation differences in APIs are as follows:
-
GetHashCode returns equal values for different methods of the same class.
-
System.DateTime.Now.Millisecond.ToString always returns zero on the Windows Phone Emulator.
-
Decimal.Parse returns an invalid decimal value when exponents are used for values near zero. On Windows, the method returns zero. For example, for the values 0E-50 and 10900E-512, an invalid decimal value is returned instead of zero.
-
GetHashCode returns 0 for some user-defined structs in .NET Compact Framework, but non-zero values in .NET Framework.
Exceptions
Some methods throw different exceptions in Silverlight applications on Windows versus Windows Phone. The following information describes this behavior on Windows.
-
If you pass an invalid flag when you create an X509Certificate, a NotSupportedException occurs instead of ArgumentException.
-
If you attempt to access a file from an FTP site, the application throws NullRefrenceException instead of NotSupportedException.
-
If you attempt to use unsupported East Asian languages, the application throws PlatformNotSupportedException instead of TypeInitializationException.
-
System.ArgumentNullException is thrown when trying to retrieve a MemoryStream of size zero bytes from a resource file. On Windows, no exception is thrown and length is equal to zero.
-
Wrapping a custom reader does not result in an InvalidOperationException. Applications must make sure the ConformanceLevel in XmlReaderSettings is set to Auto when wrapping a custom reader.
-
ArrayTypeMismatchException is not thrown when your application tries to store Stream.Null in a variable of type MemoryStream.
-
If you invoke a static constructor using reflection, the application throws ArgumentException instead of MethodAccessException.
-
When you attempt to set a non-integer value to an integer field of a base class through a derived class, Type.InvokeMember throws MissingFieldException instead of ArgumentException.
-
.NET Compact Framework throws an exception when deriving a class from Dictionary where the key parameter is an enumeration.
-
Some attribute constructor arguments and property values can cause Type.GetCustomAttributes to fail.
-
A multicast virtual function lookup delegate throws NullReferenceException in .NET Compact Framework, while AccessViolationException is thrown in .NET Framework.
-
If your application attempts to invoke a non-existing method of a type, or tries to invoke a method that has ambiguity, .NET Compact Framework throws AmbiguousMatchException.
-
If you pass an invalid path in Path.GetDirectoryName(System.String), the method does not throw an exception. For example, System.IO.Path.GetDirectoryName(@"D:\temp\ .") returns "D:\temp" instead of throwing an exception.
-
Path.GetDirectoryName(System.String) does not throw any exception when the source path is longer than the system-defined maximum path length.
-
If you pass an invalid culture for the satellite assembly in Assembly.GetSatelliteAssembly(System.Globalization.CultureInfo), the method throws FileLoadException on Windows, but it throws a FileNotFoundException on Windows Phone.
-
ArgumentException displays the message Argument Exception instead of Exception of type 'System.ArgumentException'. Similarly, ArithmeticException displays Arithmetic Exception instead of the string that is thrown on Windows.
-
ICollection.CopyTo(System.Array,System.Int32) throws ArgumentException instead of InvalidCastException.
-
FieldInfo.GetValue(System.Object) throws an ArgumentNullException when null is passed as first parameter.
-
FieldInfo.Value(Object) throws InvalidCastException when casting an object's field info value to a string using string instead of ToString().
-
System.ServiceModel.Channels.MessageHeaders.CopyHeaderFrom displays the message Specified argument was out of the range of valid values instead of The value of this argument must fall within the range 0 to 1.
-
If you pass an invalid value to Array.SetValue(System.Object,System.Int32), the method throws InvalidCaseException instead of ArgumentException.
-
Array.GetLowerBound(System.Int32) does not throw IndexOutOfRangeException when the passed in dimension is equal to the rank of the array. Instead, it returns 0 as the lower bound value.
-
If you pass an invalid input path to a StreamWriter constructor, the constructor throws InvalidArgumentException instead of DirectoryNotFoundException.
-
System.Runtime.Serialization.DataContractSerializer.ReadObject throws MethodAccessException instead of SecurityException when it attempts to deserialize an IXmlSerializable type that has a private constructor.
-
The display message for MissingMethodException is incorrect.
-
If you attempt to invoke delegates asynchronously, the application throws TargetInvocationException instead of NotSupportedException.
-
System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(System.IO.Stream) throws SecurityException in cases where a MethodAccessException should be thrown.
-
If you pass an invalid value to System.Text.RegularExpressions.MatchCollection.CopyTo(System.Array,System.Int32), the method throws ArgumentOutOfRangeException instead of ArgumentException.
-
If you pass an invalid code page name to System.Text.Encoding.GetEncoding(System.String), the method throws PlatformNotSupportedException instead of ArgumentException.
-
If you pass a null object to CreateInstance, the method throws NullReferenceException instead of NotSupportedException.
-
If you pass a string to System.Version.CompareTo, the method throws InvalidCastException instead of ArgumentException.
-
Delegate.CreateDelegate throws MissingMethodException while trying to create a delegate with incorrect arguments. On Windows, the method does not throw an exception; it returns null.
-
Type.MakeByRefType does not throw TypeLoadException when the MakeByRefType method for a ByRef type is called.
-
The DateTime.ParseExact method accepts an incorrect time instead of throwing FormatException, while on Windows FormatException is thrown, which indicates that the time was not a valid DateTime.
-
CompareInfo.Compare() does not throw the expected exception, ArgumentException, if you pass an invalid CompareOptions object.
-
XmlReader does not fail when numeric character entity computation overflows. Instead, an empty string is returned to XmlReader.Value.
-
Message.ToString() shows different behavior on Windows Phone. Message.ToString() does not show XML version information in .NET Compact Framework.
-
MethodBase.GetMethodFromHandle does not throw any exception when an invalid handle is passed as input. Instead, it returns null.
-
Module.GetType does not throw ArgumentException when an empty string is passed as name of the type. Instead, it returns null.
-
Assembly.LoadFrom(String) fails when you try to load a file that is not a valid assembly. This behavior is by design; the failure occurs during metadata validation to prevent loading of a corrupt image.
-
Type.GetProperty throws NullReferenceException instead of ArgumentNullException when the array representing the parameter types contains a null element.
-
Assembly.GetType throws System.TypeLoadException instead of System.ArgumentException when the string value is null.
-
Type.GetConstructor(BindingFlags, Binder, Type[], ParameterModifier[]) throws ArgumentNullException when no ParameterModifiers are specified (NULL is passed). On Windows, no exception is thrown.
-
Path.GetRootPath returns an empty string when the input is prefixed with whitespace.
-
FieldInfo.SetValue() throws an ArgumentNullException instead of TargetException when null is passed as the first parameter.
-
EventInfo.AddEventHandler throws ArgumentNullException instead of TargetException when passing null as the first parameter or eventinfo is not declared on target
-
EventInfo.AddEventHandler throws ArgumentNullException instead of InvalidOperationException when the event does not have a public add accessor.
-
MethodBase.Invoke does not throw TargetException in somes scenarios; it may throw an unexpected exception instead.
-
If you pass an invalid parameter to Type.GetType(typeName, throwOnError), the method throws an unexpected exception instead of ArgumentException.
-
If you pass invalid values to PropertyInfo.GetValue, the method throws an ArgumentNullException instead of TargetException.
-
If the count of indexes is less than the real count, PropertyInfo.GetValue throws ArgumentException instead of TargetParameterCountException.
-
If the assemblyFile parameter is not a valid assembly, the Assembly.LoadFrom (String) method throws System.IO.IOException instead of BadImageFormatException.
-
If you use FieldInfo.SetValue() on a public const field, the method throws System.MemberAccessException instead of FieldAccessException.
-
For types that do not have constructors defined, System.Activator.CreateInstance(Type, object[]) throws MemberAccessException instead of MissingMethodException.
-
If you pass an invalid parameter to Module.ResolveMethod, the method throws ArgumentException instead of ArgumentOutofRangeException.
-
Type.GetMethods throws InvalidProgramException if one of the methods contains a type will not be available in run time.
-
If you pass an invalid string to Assembly.Load(), it throws System.IO.IOException instead of ArgumentException.
-
Type.InvokeMember throws MissingFieldException when the name argument contains a wildcard character.
-
ConstructorInfo.Invoke throws ArgumentException instead of TargetParameterCountException when there is a mismatch in the number of arguments.
-
If you pass an invalid string to AssemblyName(string) constructor, the constructor throws FileLoadException instead of IOException.
-
If you pass an invalid name to Assembly.GetType(string name), the method does not throw ArgumentException, but instead returns a null type.
-
If you set CultureInfo("fr").NumberFormat.CurrencySymbol to "USD", it throws NotSupportedException.
-
Decimal.Parse(String format, int style) returns 0 for infinitesimally small values on Windows, but returns OverlowException on Windows Phone.
-
Decimal.Parse(String, NumberStyles) throws OverflowException if you pass a larger than supported value. No exception is thrown on Windows.
-
DCS.WriteObject() fails when it tries to serialize an inner type that contains a type derived from Dictionary<TKey, TValue> because open generics are not supported.
-
XmlException.LineNumber and XmlException.LinePosition values are incorrectly returned in XmlException.
-
Acquiring the type using the ReturnParameter property from a MethodInfo object throws NotSupportedException.
-
If you pass an invalid parameter to System.String.IndexOfAny, the method throws ArgumentOutOfRangeException instead of ArgumentNullException.
-
CultureInfo(string) constructor throws PlatformNotSupportedException instead of ArgumentException for unsupported cultures