.NET手记

.NET学习

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
Important! migrating older code to the newer release

If you are migrating Silverlight applications that were created for the Silverlight 2 Beta 2 release or earlier to the final release of Silverlight 2, you must get the newest Silverlight 2 Tools for Visual Studio 2008 and recompile your project(s).

  1. Get the newest version of Silverlight 2 Tools for Visual Studio 2008. You can get these tools from the SDK or online at Getting Started. You may have to uninstall any old tools before doing this installation.

  2. Open your old project (for example, .csproj file). A dialog box will come up notifying you that your project was created by using an older version of Silverlight tools and asks you if you want to upgrade your project. Click the Yes button.

  3. Debug. Many of the breaking changes you are likely to encounter can be found in this document.

 

ContentPresenter now derives from FrameworkElement instead of Control

Who Is Affected: Applications that use ContentPresenter or objects derived from ContentPresenter.

Summary

Because ContentPresenter now derives from FrameworkElement, the following properties are no longer exposed by ContentPresenter:

  • Background

  • BorderBrush

  • BorderThickness

  • DefaultStyleKey

  • FontFamily

  • FontSize

  • FontStretch

  • FontStyle

  • FontWeight

  • Foreground

  • HorizontalContentAlignment

  • IsEnabled

  • IsTabStop

  • Padding

  • TabIndex

  • TabNavigation

  • Template

  • VerticalContentAlignment

 

Fix Required

Remove all these obsolete properties from your ContentPresenter objects, which will likely require that you re-work some of your code to restore your previous UI rendering.

Layout rendering slightly changed

Who Is Affected: All content using layout might be rendered slightly differently because layout no longer causes elements to be rendered at subpixel locations.

Summary

The layout system in Silverlight has been modified to round final measure and arrange values to integers when positioning elements on the screen ("pixel snapping"). The result is crisper lines, more consistent rendering look, and fewer rendering artifacts.

By default, layout rounding will be on, but there is a new inherited property on UIElement called UseLayoutRounding that can be set to false if the old layout behavior is desired.

Note:

It is possible that this change will affect how your animations render, in which case you might want to set UseLayoutRounding to false.

Note:

This change does not affect transforms. If you apply a transform to an element, it may still be rendered at a subpixel location.

 

 

Cross domain hosts of Silverlight must set the right MIME type for XAP (application/x-silverlight-app)

Who Is Affected: Anyone serving Silverlight 2 applications from cross domain:

  • Via a Web server that is not IIS7

  • Via a Web server where the MIME type for .XAP files is incorrectly configured

Summary/Fix Required

When the XAP is served from a different domain than the host HTML page, Silverlight will validate that the MIME type (Content-Type response header) returned on the HTTP response is application/x-silverlight-app.

Apache (and perhaps other servers) typically serve unrecognized content as text/plain, and therefore will be affected by this change. You are required to add an entry for the Silverlight XAP MIME type to your .htaccess file. For example, AddType application/x-silverlight-app xap.

 

Note:

IIS7 included the correct MIME type configurations for Silverlight XAPs. No action is required if you are using IIS7.

Exceptions now thrown in HttpWebRequest.EndGetResponse()

Who Is Affected: Silverlight 2 applications that use HttpWebRequest.

Summary/Fix Required

For HttpWebRequest:

Before:

  • Some security exceptions (for example, cross-scheme violations) were being raised in HttpWebRequest.BeingGetResponse()

  • All other request error conditions were being returned as 404s.

Now:

  • Error conditions are now raised as exceptions in HttpRequest.EndGetResponse().

    • Request security errors (for example, requests not allowed by cross domain policy) raise SecurityExceptions

    • Non-successful requests (for example, those that returned 404 error messages) raise WebExceptions. The WebException.Response is set to HttpStatusCode.NotFound. This is compatible with the desktop.

Font URI is restricted to assembly resource

What Is Affected: Silverlight 2 Beta 1 or Beta 2 applications (not Silverlight 1.0 applications) that reference fonts (or collections of fonts) by way of the URI syntax in the Control.FontFamily, TextBlock.FontFamily or Glyphs.FontUri attributes and where the fonts are not embedded in the assembly (.dll) of the control or application.

Fix Required

You can specify a font (or in some cases a zip of fonts) in URI format through the Control.FontFamily, TextBlock.FontFamily and the Glyphs.FontUri attributes. If you are, you will have to make sure that your font is marked as a "resource" in the project system.

Browser.HtmlElementCollection replaced with by Browser.ScriptObjectCollection

What Is Affected: Silvlierlight 2 Beta 2 applications that use the HTML bridge HtmlElementCollection will break if this change is checked in. The type has been replaced with a new type: ScriptObjectCollection.

Summary

The System.Windows.Browser.HtmlElementCollection type was changed to ScriptObjectCollection. All previous references to HtmlElement on the collection have been changed to instead reference ScriptObject. Other areas of the HTML bridge that previously used HtmlElementCollection (that is HtmlElement.Children) have been switched to instead return a ScriptObjectCollection. Note that if you retrieve an item from the new ScriptObjectCollection that is actually an HtmlElement, you can still cast the return value back to an HtmlElement.

The specific benefit from this change is that across all browsers you can now access both element and non-element DOM nodes that are contained in a node collection. We made this change because there is no consistent cross-browser implementation of a HtmlElement-specific collection type.

Fix Required

Change existing references to HtmlElementCollection to ScriptObjectCollection. If your existing code was working with HtmlElement return values, you must explicitly cast the items returned from a ScriptObjectCollection to an HtmlElement. Since the collection type is now ScriptObjectCollection it is likely that on different browsers the ordinality of the resulting collection will also change. Any code that was relying on fixed offsets into the collection may have to be changed to account for non-element nodes (for example, text nodes such as whitespace, etc…) in the collection.

Beta 2

C# Code
HtmlElement myHtmlElement = someOtherHtmlElement.Children[5];

 

Release

C# Code
HtmlElement myHtmlElement = (HtmlElement)someOtherHtmlElement.Children[5]; //assuming the desired element is still at offset 5

Exceptions when changing some properties on an Active Animation

What Is Affected: Silverlight 1.0 and 2.0 applications that change properties on active animations.

Summary

When you change one of the properties in the following list on an active Storyboard, an exception is raised at runtime with this message: “Operation is not valid on an active Animation or Storyboard. Root Storyboard must be stopped first."

The list of properties that cannot be modified on an active animation or Storyboard are in the following list:

Attached Properties

  • Storyboard.TargetNameProperty

  • Storyboard.TargetPropertyProperty

Properties on derived classes from Timeline of a collection type

  • Storyboard.Children (you cannot add/remove animations from an active storyboard)

  • ColorAnimationUsingKeyFrames.KeyFrames

  • DoubleAnimationUsingKeyFrames.KeyFrames

  • PointAnimationUsingKeyFrames.KeyFrames

  • ObjectAnimationUsingKeyFrames.KeyFrames

Make sure that you stop the Storyboard before changing one of these properties. You can do this by using the Storyboard.Stop method.

System.Windows.Controls.Extended.dll renamed to System.Windows.Controls.dll

Who Is Affected: Anyone who uses the extended controls (Calendar, DatePicker, TabControl and GridSplitter).

Fix Required

Change all references from System.Controls.Extended to System.Windows.Controls and recompile your application.

VisualStateManager changes

Who Is Affected: Silverlight 2 applications that use VisualStateManager.

Summary

VisualTransition.Duration has changed to VisualTransition.GeneratedDuration. This value will now only affect the generated transitions, and not the VisualTransition.Storyboard.

Example:

In the XAML shown here, the VSM generated animations for the Pressed-> Normal transition will be created with 1 second durations. The explicit transition Storyboard with its blue ColorAnimation will still be 2 seconds.

XAML Code
<vsm:VisualStateGroup x:Name="CommonStateGroup">
                        ...
                        <vsm:VisualStateGroup.Transitions>
                        ...
                        <vsm:VisualTransition From="Pressed" To="Normal" GeneratedDuration="0:0:1">
                        <Storyboard>
                        <ColorAnimation Storyboard.TargetName="MainRect"  Duration="0:0:2"
                        Storyboard.TargetProperty="Fill" SpeedRatio="2" To="Blue"/>
                        </Storyboard>
                        </vsm:VisualTransition>
                        </vsm:VisualStateGroup.Transitions>
                        </vsm:VisualStateGroup>

VisualStateManager.CustomVisualStateManager should be set on the root visual of the ControlTemplate or UserControl, not the Control/UserControl itself. In the following example, the custom visual state manager is set on the Grid, the ControlTemplate’s root visual.

XAML Code
<ControlTemplate  TargetType="local:CheckBox">
                        <Grid x:Name="RootElement" HorizontalAlignment="Center"
                        VerticalAlignment="Center" Background="Transparent">
                        <vsm:VisualStateManager.CustomVisualStateManager>
                        <local:MyVisualStateManager>
                        </vsm:VisualStateManager.CustomVisualStateManager>
                        ...
                        </Grid>
                        </ControlTemplate>
posted on 2008-10-22 16:02  baggiojing  阅读(577)  评论(0编辑  收藏  举报