
This topic describes the implementation differences between Silverlight 3 on Windows and Silverlight on Windows Phone.
I advise you to get acquainted with what
supports Silverlight on Windows Phone , as well as to get more detailed information about
types and members that are
not supported .
ControlsTo view the list of supported controls, it is better to read a
separate article .
MediaIn this case, again I advise you to turn to the original source
Media on Mobile Phone .
')
Deep zoomSilverlight for Windows Phone always uses hardware acceleration in
MultiScaleImage , if possible. As a result, any changes to the
CacheMode property
are ignored.
DelegatesAsynchronous delegates, especially the
BeginInvoke and
EndInvoke methods , are not supported in the .NET Compact Framework. If you try to call delegates asynchronously, the application will throw a
TargetInvocationException instead of a
NotSupportedException .
FinalizersControl Restricted Areas (CER) are not supported in Silverlight for Windows Phone.
FontsAll fonts that are available go already from ROM. No fonts are installed with Silverlight. It is recommended to use web safe fonts such as Verdana and Segoe. Visual Studio 2010 Express for Windows Phone CTP includes filters that display supported fonts on Windows Phone 7 Series. If you wish to use fonts that are not present on the device, it is recommended to ship them with the application. TrueType fonts are also recommended. Embedded fonts should be added to a DLL or XAP, as embedded resources for runtime support in managed code.
GraphicsSupports graphics, animation, and effects such as
Blur and
DropShadow . All effects in Silverlight for Windows Phone can use hardware acceleration, therefore you must set the
UIElement's CacheMode to
BitmapCache .
Own pixel shaders are not supported, hence
PixelShader is also not supported. More detailed information about
graphics and
animation .
AccommodationAll Silverlight applications on Windows Phone are stored on the client device and are
not executed inside the browser. All the functionality of Silverlight, which is based on location in the browser - is not available. This includes HTML DOM bridges, the ability to use JavaScript and a
link to the plugin objectInputThe controls support various gestures such as touching, pressing, “driving” with your finger. You can handle simple movements: pressing, double pressing, pressing and holding, using mouse events:
- MouseLeftButtonUp to touch
- To handle double clicks, check if you click twice in a certain amount of time ( TimeSpan ). If the MouseMove event did not occur between clicks, then double-click occurred.
- To handle the hold and hold, start the TimeSpan timer on the MouseLeftButtonDown event and save the touch coordinates. In the MouseMove event, check if the user's touch shifted a few pixels. If shifted, cancel the timer. If the MouseLeftButtonUp event occurs before the timer expires, also cancel the timer. If the timer expired before cancellation - clamping occurred.
You can also use control events to respond to user input. Control events support multi-touch input and can be used to move and scale
UIElement objects. In addition, see
How to: Handle Manipulation Events .
Isolated StorageIsolated storage allows an application to store data in a virtual file system. The data is completely fenced off from other system components. This prevents unauthorized access and data corruption by components of another application that stores data.
Isolated storage on Windows Phone does not impose additional quotas on the size limit of storage for Silverlight applications.
The size of the application on Windows Phone can reach up to 2 GB.
The differences between implementation on platforms are as follows:
- Isolated storage on Windows Phone does not include the concept of the site, so GetUserStoreForSite is not supported.
- IncreaseQuotaTo throws an exception
- The constructor of the class IsolatedStorageFileStream does not support the FileShare.Delete and FileShare.Inheritable properties due to platform limitations
- The maximum quota size for an application is MAXLONG by default.
You can read more about isolated storage in the following articles:
Isolated Storage and
System.IO.IsolatedStorageLINQLINQ providers for native data sources are not supported in Silverlight for Windows Phone.
LocalizationSome types and members that support localization work somewhat differently:
- Own culture returns standard formatting when custom formatting is expected. For example, 08/31/2006 12:30:15 will return as 8/31/06 12:30:15 PM.
- You cannot use a neutral culture when formatting and parsing, therefore, you cannot set a neutral culture as the current culture of a stream.
- DateTimeFormatInfo.GetEra returns -1 for fr-FR culture
- The DateTimeFormatInfo.GetEraName method returns an incorrect value in some cases. The same fr-FR localization string DC, instead of the expected AD
- DateTime.ToString returns an incorrect string for Russian dates. For example, we get June 15, 2000, instead of June 15, 2000.
- Double.ToString () does not return a valid string containing comma delimiters between groups of numbers when using its own format.
Multisensory and control eventsTo work with melt-sensory and manipulation events, Silverlight on Windows Phone supports types, members, and events that are not represented in Silverlight 3. For more information, read
How to: Handle Manipulation EventsNavigationSilverlight on Windows Phone provides page navigation models other than Windows.
Frame and
Page classes are not supported. For more information, see the
Frame and Page Navigation topic
.NetworkNetworking support includes the Windows Communication Foundation (WCF),
HttpWebRequest, and
WebClient .
Own connections and sockets are not supported. Because
ChannelFactory (TChannel) is not supported and you cannot generate proxies dynamically. You must use slsvcutil.exe in the console to generate powers of attorney at the time of compilation.
The Add Service Reference option in Visual Studio also generates proxies that you can connect at compile time. This option is not available in Windows Phone projects in the Community Technology Preview version.
The
Style property of the
XmlSerializerFormatAttribute class is not supported.
This is not all not supported features, it is written in more detail
here .
PerformanceDevices have less processor power, storage and memory than desktop computers. They also have limited battery life. You must design applications considering these facts, especially for those applications that use animation and media. Some devices can slow down if you use multiple
Storyboard objects or by manipulating a large number of XAML elements.
To optimize XAML code while applying complex transformations, Silverlight on Windows Phone supports
CompositeTransform .
ReflectionThe implementation of reflection (reflection) is different from the desktop:
- Some types and members are not supported, the list can be found in Class Library Support on Windows Phone
- Open generic types are not supported.
- The ignoreCase parameter in the GetType method is not supported. You must use case-sensitive type names.
- The behavioral and functional difference is also present in the binder implementation in Silverlight 3 and the .NET Compact Framework.
- Equivalence operator (==) does not return true for two MethodInfo objects.
- The System.Reflection.Emit namespace is not supported.
- GetNestedTypes returns all nested types, regardless of the value of the BindingFlags .
- AssemblyName.GetPublicKeyToken returns null instead of byte [0] for byte [0] PKT or for the name of an assembly containing PublicKeyToken = null.
- For the declaringType parameter, MethodBase.GetMethodFromHandle (MethodHandle, TypeHandle) uses RuntimeMethodHandle instead of RuntimeTypeHandle .
- WaitHandle.WaitAll is not supported in the .NET Compact Framework.
- AssemblyName (). ToString () and Assembly.FullName returns the System.Reflection.AssemblyName when using the standard constructor to initialize the AssemblyName object
- ParameterInfo.DefaultValue returns null
- The Type.GetMember method does not return any public members with the specified name if the name is specified by a regular expression.
- The Type.GetMethods and Type.GetMembers methods do not return the same object instance.
- AssemblyName.FullName does not return the PublicKeyToken default information. The .NET Compact Framework provides only the name of the assembly. You must use separate methods to compare cultures, versions, and PKT information.
- FieldInfo.ToString () returns System.Boolean [] instead of Boolean [] when it points to bool.
- Type.GetMethod (String, Type []) returns null MethodInfo values for the Set (Int32, System.String) method, while the desktop returns MethodInfo , which is not null at all.
- The return value for Type.AssemblyQualifiedName differs between platforms. for example, the return value for AssemblyQualifiedName on Silverlight under Windows Phone might look like this: MyType, MyAssembly, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = b17a5c561934e089 . Its equivalent on the desktop: MyType, MyAssembly, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = B17A5C561934E089
Regular expressionsIn Silverlight for Windows Phone, the CacheSize property always returns zero, because the implementation of the Regex class does not support caching.
RuntimeSilverlight under Windows Phone 7 Series runs on the .NET Compact Framework.
SecurityThe difference is with X509 certificates, if you pass an invalid flag when you create an X509Certificate, a NotSupportedException is thrown instead of an
ArgumentException .
SipTo be able to use the software input panel (SIP) for the
TextBox control, Silverlight for Windows Phone 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 .
Silverlight Extensions for Windows PhoneFor additional features that are specific to development for Windows Phone, again read the
Class Library Reference for Windows Phone . All this functionality is included in Windows Phone Developer Tools.
Text encodingsEncoding.Unicode encoder renamed to System.Text.UnicodeEncoding and UnicodeEncoder.
Encoding.Unicode decoder renamed to System.Text.UnicodeEncoding and UnicodeDecoder
StreamsUnlike Silverlight 3, Silverlight for Windows Phone divides the animation work into two separate streams to improve device performance.
ThreadStaticAttribute is not used in the .NET Compact Framework.
URIsThe
HttpUtility class is in the
System.Net namespace. On Windows, this class is in the
System.Windows.Browser namespace , which is not supported on the Windows Phone platform.
Uri.LocalPath does not convert a slash (/) to a backslash (\). Because URIs for files (file: //) are not allowed. The paths are returned as relative.
The
OriginalString property for
URI instances truncates spaces before being passed to a URL.
Visual basicIn the .NET Compact Framework, the syntax of LINQ queries in Visual Basic does not support the Select clause, where the statement is optional. If the Select clause does not include parameters that do not change the standard result of the query, you must remove the Select clause.
Visual Basic is not supported in this release.Visual Basic cannot execute equality check with references of XNamespace and String objects at runtime.
XAML transformationsTo optimize XAML when you apply multiple transformations, Silverlight on Windows Phone supports
CompositeTransform .
XMLParsing is not supported due to the fact that the .NET Compact Framework does not support the definition of a document type (DTD). The application throws NotSupportedExeption when it detects a DTD string in XML. To parse a DTD, an application must implement a recognition mechanism or use XML schemas.
Frequently used DTDs are usually run through
XmlPreloadedResolver . This type is present in the Silverlight 3 SDK, but is not supported in the Community Technology Preview version.
The following differences are also present:
- Serialized output of an XmlSerializer of type XmlQualifiedName is not fully formed.
- The .NET Compact Framewrok allows wrapping in its own classes for reading. You can create your own class for reading, with your own implementation of the necessary functions and then pass it on to the input to XmlReader.Create (XmlReader, XmlReaderSettings)
Other differencesThere are a few more limitations in the API:
- GetHashCode returns the same values for different methods of the same class.
- System.DateTime.Now.Millisecond.ToString always returns zero in the Windows Phone Emulator
- Decimal.Parse returns an invalid decimal value when the exponent is close to zero. On Windows, the method returns zero. For example, for the value 0E-50 and 10900E-512 invalid decimal values are returned instead of zero.
- GetHashCode returns 0 for some user-declared structures in the .NET Compact Framework, and non-zero in the .NET Framework.
ExceptionsSome methods throw different exceptions depending on the platform:
- If you pass an invalid flag when creating an X509Certificate, a NotSupportedExeption is thrown instead of an ArgumentException .
- If you try to access the file with FTP, the application will throw a NullReferenceExeption instead of a NotSupportedException
- If you try to use unsupported East Asian languages, the application will throw a PlatformNotSupportedException instead of a TypeInitializationException
- System.ArgumentNullException is thrown when we try to return a MemoryStream of size to zero bytes from the resource file. In Windows, no exception appears.
- Wrapping up in its own class for reading, the application should make sure that the ConformanceLevel in XmlReaderSettings is set to Auto.
- ArrayTypeMismatchException appears when an application tries to save a Stream.Null in a variable of type MemoryStream
- If you call a static constructor using reflection, the application will throw an ArgumentException instead of a MethodAccessException .
- When you try to set a non-integer value to a field for a base class through a Type.InvokeMember heir, throw MissingFieldException instead of ArgumentException .
- The .NET Compact Framework throws an exception when a class is inherited from a Dictionary , where the key parameter is an enumeration.
- Some attributes of constructor arguments and property values can cause Type.GetCustomAttributes to crash .
- Looking up group delegates for virtual functions throws a NullReferenceException into the .NET Compact Framework, whereas in the .NET Framework we get AccessViolationException
- If your application tries to call a nonexistent type method or tries to call a method with uncertainty, the .NET Compact Framework will throw an AmbiguousMatchException .
- If you pass the wrong path to Path.GetDirectoryName (System.String) , the method will not throw an exception. For example, System.IO.Path.GetDirectoryName (@ "D: \ temp \.") Returns "D: \ temp", not an exception.
- Path.GetDirectoryName (System.String) does not even throw an exception. if the path is longer than the maximum allowed in the system.
- If you pass an invalid culture to the Assembly.GetSatelliteAssembly (System.Globalization.CultureInfo) satellite assembly, the method will throw FileLoadException in Windows and FileNotFoundException on Windows Phone
- ArgumentException displays the message Argument Exception instead of Exception of type 'System.ArgumentException' . Similarly, an ArithmeticException displays an Arithmetic Exception instead of displaying a string, as in Windows.
- ICollection.CopyTo (System.Array, System.Int32) throws an ArgumentException instead of an InvalidCastException
- FieldInfo.GetValue (System.Object) throws an ArgumentNullException when null is passed as the first parameter.
- FieldInfo.Value (Object) throws an InvalidCastException when it converts an object's information field value to a string using string instead of ToString ().
- System.ServiceModel.Channels.MessageHeaders.CopyHeaderFrom displays the message instead of 0 to 1 .
- If you pass an invalid Array.SetValue (System.Object, System.Int32) , the method will throw an InvalidCaseException instead of an ArgumentException .
- Array.GetLowerBound (System.Int32) will not throw an IndexOutOfRangeException if the passed measurement is equal to the array bit. Instead, it returns 0 as the lower bound value.
- If you pass an invalid path to the StreamWriter constructor, it will throw an InvalidArgumentException instead of a DirectoryNotFoundException .
- System.Runtime.Serialization.DataContractSerializer.ReadObject throws MethodAccessException instead of SecurityException when an attempt is made to deserialize the type IXmlSerializable, which has a private constructor.
- The message displayed for MissingMethodException is not correct.
- If you try to call the delegate asynchronously, the application will throw a TargetInvocationException instead of a NotSupportedException
- System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.IO.Stream) will throw a SecurityException when a MethodAccessException is expected.
- If you pass an erroneous value to System.Text.RegularExpressions.MatchCollection.CopyTo (System.Array, System.Int32), the method will throw PlatformNotSupportedException instead of ArgumentException
- If you pass a null object to CreateInstance, the method will throw a NullReferenceException instead of NotSupportedException
- If you pass a string to System.Version.CompareTo, the method will throw an InvalidCastException instead of an ArgumentException .
- Delegate.CreateDelegate throws a MissingMethodException if you try to create a delegate with the wrong arguments. In Windows, the method does not throw any exceptions, but returns null.
- Type.MakeByRefType will not throw a TypeLoadException if the MakeByRefType method is called for a ByRef type.
- The DateTime.ParseExact method can take an incorrect time and will not throw FormatException exceptions, while on Windows you will receive a FormatException
- CompareInfo.Compare () will not throw an expected ArgumentException exception if you pass an invalid CompareOptions object.
- The XmlReader will not crash when the numeric character calculation overflows. Instead, it returns an empty string in the XmlReader.Value.
- Message.ToString () works differently on Windows Phone. Message.ToString () does not display the XML version information in the .NET Compact Framework.
- MethodBase.GetMethodFromHandle does not throw exceptions, if you pass the wrong handler to the input. It will simply return null.
- Module.GetType does not throw an ArgumentException exception, if you pass an empty string, type name. It will simply return null.
- Assembly.LoadFrom (String) crashes if you try to pass a file to the load that is not an assembly. It was specially designed, it happens at the moment of metadata validation, to prevent the loading of damaged images.
- Type.GetProperty will throw a NullReferenceException instead of ArgumentNullException when the presented parameter types contain null-elements.
- Assembly.GetType will throw a System.TypeLoadException instead of System.ArgumentException if the string value is null.
- Type.GetConstructor (BindingFlags, Binder, Type [], ParameterModifier []) will throw an ArgumentNullException if ParameterModifiers or null is not specified.
- Path.GetRootPath will return an empty string if the input data begins with a space.
- FieldInfo.SetValue () will throw an ArgumentNullException instead of a TargetException if you pass null to the first parameter.
- EventInfo.AddEventHandler will throw an ArgumentNullException instead of a TargetException if you pass null to the first parameter.
- EventInfo.AddEventHandler will throw an ArgumentNullException instead of an InvalidOperationException if the event does not have a public add accessor.
- In some situations, MethodBase.Invoke will not throw a TargetException , but may throw an unexpected exception.
- If you pass incorrect parameters to Type.GetType (typeName, throwOnError), the method throws an unexpected exception instead of ArgumentException .
- If you pass incorrect values in PropertyInfo.GetValue, the method throws ArgumentNullException instead of TargetException .
- If the number of indexers is less than the actual number, PropertyInfo.GetValue will throw out ArgumentException instead of TargetParameterCountException .
- If the assemblyFile parameter is not a valid assembly, Assembly.LoadFrom (String) will throw a System.IO.IOException instead of a BadImageFormatException .
- If you use FieldInfo.SetValue () for a public constant field, the method will throw System.MemberAccessException instead of FieldAccessException .
- For those types that do not have a constructor declared, System.Activator.CreateInstance (Type, object []) will throw a MemberAccessException instead of a MissingMethodException .
- If you pass an invalid parameter to Module.ResolveMethod, the method will throw out ArgumentException instead of ArgumentOutofRangeException .
- Type.GetMethods will throw an InvalidProgramException if one of the methods contains a type that is not available at runtime.
- If you pass an invalid string to Assembly.Load (), it will throw out a System.IO.IOException instead of an ArgumentException .
- Type.InvokeMember will throw a MissingFieldException if the argument name contains a wildcard character.
- ConstructorInfo.Invoke will throw an ArgumentException instead of a TargetParameterCountException if there is no match for the number of arguments.
- If you pass an invalid string to the AssemblyName (string) constructor, it will throw out a FileLoadException instead of an IOException .
- If you pass an invalid name to Assembly.GetType (string name), the method will not throw an ArgumentException , but return null.
- If you set CultureInfo ("fr"). NumberFormat.CurrencySymbol to "USD", then you will get a NotSupportedException .
- Decimal.Parse (String format, int style) returns 0 infinitely small values in Windows, on Windows Phone you get an OverlowException .
- Decimal.Parse (String, NumberStyles) will throw an OverflowException if passed more than a supported value. Again, you will not see any exception in Windows in this case.
- DCS.WriteObject () will fall if you try to serialize an internal type that contains a type inherited from Dictionary <TKey, TValue> because open generic types are not supported.
- XmlException.LineNumber and XmlException.LinePosition values do not correctly return to XmlException.
- When you get a type using the ReturnParameter property of the MethodInfo object, you will stumble upon a NotSupportedException exception.
- If you pass incorrect parameters to System.String.IndexOfAny, the method will throw out ArgumentOutOfRangeException instead of ArgumentNullException
- The CultureInfo (string) constructor will throw a PlatformNotSupportedException instead of an ArgumentException for unsupported cultures.