- 重要事项!将较旧的代码迁移到较新的发行版本
- ContentPresenter 现在从 FrameworkElement 而非 Control 派生
- 布局呈现略有变化
- Silverlight 的跨域宿主必须为 XAP 设置正确的 MIME 类型 (application/x-silverlight-app)
- 现在在 HttpWebRequest.EndGetResponse() 中引发异常
- 将字体 URI 限制为程序集资源
- Browser.HtmlElementCollection 被 Browser.ScriptObjectCollection 替代
- 更改活动动画上的一些属性时出现异常
- System.Windows.Controls.Extended.dll 已重命名为 System.Windows.Controls.dll
- VisualStateManager 更改
- 同步发送 KeyDown
- Canvas 的 MeasureOverride/ArrangeOverride 现在已密封
- UriTypeConverter 已移到 System.dll
- HtmlPage.UnregisterScriptableObject 已移除
- RenderingEventArgs 更改
- ContentPresenter 和 ContentControl 更改
- 移除 FileDialogFileInfo 类型和 OpenFileDialog.SelectedFile(s) 属性
- 在 Silverlight 2 应用程序清单中移除了针对 ExternalCallersFromCrossDomain 属性的 FullAccess 选项
- KeyFrameCollection 更改
- 在调用 HttpWebRequest.BeginGetResponse() 前必须关闭请求流
- Safari/Mac 上的 HtmlWindow 引用的计算结果不再为 true
- Address 属性已从所有 WebClient EventArg 类中移除
- 构造函数变为内部的
- System.Xml 异常类型发生更改
- 不能在 XAML 中创建不具有可用构造函数的类
- 在 Silverlight 2 中获取 AG_E_UNKNOWN_ERROR 但不在 Silverlight 1 中获取
- 平台将 generic.xaml 作为 themes/generic.xaml 上的资源查找
- HTTP 轮询双工 OM 发生更改并重新进行工程设计
- 对承载 IXcpControl COM 接口的 Silverlight 本机的重大更改
- 其他 API 更改
如果您正在将为 Silverlight 2 Beta 2 或更早的发行版本创建的 Silverlight 应用程序迁移到 Silverlight 2 的最终发行版本,必须获取用于 Visual Studio 2008 的最新 Silverlight 2 工具并重新编译您的项目。
-
获取用于 Visual Studio 2008 的 Silverlight 2 工具最新版本。可以从 SDK 获取这些工具或在线获取,网址为:Getting Started(入门)。在安装此工具前可能必须卸载所有旧工具。
-
打开您的旧项目(例如 .csproj 文件)。将显示一个对话框,通知您您的项目是使用旧版本的 Silverlight 工具创建的,询问您是否要升级项目。单击“是”按钮。
-
调试。在本文档中可以找到您可能遇到的很多重大更改。
影响的对象:使用 ContentPresenter 或从 ContentPresenter 派生的对象的应用程序。
由于 ContentPresenter 现在从 FrameworkElement 派生,因此,以下属性不再由 ContentPresenter 公开:
-
Background
-
BorderBrush
-
BorderThickness
-
DefaultStyleKey
-
FontFamily
-
FontSize
-
FontStretch
-
FontStyle
-
FontWeight
-
Foreground
-
HorizontalContentAlignment
-
IsEnabled
-
IsTabStop
-
Padding
-
TabIndex
-
TabNavigation
-
Template
-
VerticalContentAlignment
需要修复
从您的 ContentPresenter 对象移除所有这些过时的属性,这可能需要您重写部分代码以恢复以前的 UI 呈现。
影响的对象:使用布局的所有内容在呈现方式上可能略有不同,因为布局不再导致在子像素位置上呈现元素。
已修改 Silverlight 中的布局系统,使它在屏幕上定位元素(“像素对齐”)时能将最终测量和排列值舍入为整数。这将使线条更鲜亮、呈现外观更一致且呈现效果更贴近自然。
默认情况下,布局舍入处于打开状态,但是 UIElement 上有一个新的名为 UseLayoutRounding 的继承属性,如果需要旧的布局行为,可以将该属性设置为 false。
|
---|
此更改将可能影响您的动画的呈现方式,在这种情况下您可能需要将 UseLayoutRounding 设置为 false。 |
|
---|
此更改不影响变换。如果您将变换应用到元素,它可能仍在子像素位置呈现。 |
影响的对象:处理跨域的 Silverlight 2 应用程序的任何服务器:
-
通过不是 IIS7 的 Web 服务器
-
通过没有为 .XAP 文件正确配置 MIME 类型的 Web 服务器
摘要/需要修复
从与宿主 HTML 页不同的域处理 XAP 时,Silverlight 将验证 HTTP 响应中返回的 MIME 类型(Content-Type 响应标头)是否为 application/x-silverlight-app。
Apache(可能还有其他服务器)一般将无法识别的内容作为文本/纯文本处理,因此将受此更改的影响。您需要将 Silverlight XAP MIME 类型的条目添加到 .htaccess 文件,例如 AddType application/x-silverlight-app xap。
|
---|
IIS7 已包含用于 Silverlight XAP 的正确 MIME 类型配置。如果您使用的是 IIS7,则不需要执行任何操作。 |
影响的对象:Silverlight 2 Beta 1 或 Beta 2 应用程序(非 Silverlight 1.0 应用程序),这些应用程序通过 URI 语法使用 Control.FontFamily、TextBlock.FontFamily 或 Glyphs.FontUri 属性引用字体(或字体集合)且这些字体未在控件或应用程序的程序集 (.dll) 中嵌入。
需要修复
可以通过 Control.FontFamily、TextBlock.FontFamily 和 Glyphs.FontUri 属性采用 URI 格式指定字体(在某些情况下为字体集合)。如果这样做,必须确保将您的字体标记为项目系统中的“资源”。
影响的对象:如果签入此更改,使用 HTML bridge HtmlElementCollection 的 Silvlierlight 2 Beta 2 应用程序将中断。此类型已被新类型 ScriptObjectCollection 替代。
System.Windows.browser.HtmlElementCollection 类型已更改为 ScriptObjectCollection。集合上所有以前对 HtmlElement 的引用已更改为引用 ScriptObject。以前使用 HtmlElementCollection(即 HtmlElement.Children)的 HTML bridge 的其他区域已更改为返回 ScriptObjectCollection。请注意,如果从实际是 HtmlElement 的新 ScriptObjectCollection 检索项,仍可以将返回值强制转换回 HtmlElement。
此更改带来的好处是您现在可以跨所有浏览器同时访问包含在节点集合中的元素和非元素 DOM 节点。我们做这个更改就是因为 HtmlElement 特定的集合类型没有一致的跨浏览器实现。
需要修复
将对 HtmlElementCollection 的现有引用更改为 ScriptObjectCollection。如果现有代码正在使用 HtmlElement 返回值,必须显式将从 ScriptObjectCollection 返回的项强制转换为 HtmlElement。由于集合类型现在为 ScriptObjectCollection,在不同的浏览器上最终集合的序数可能也会更改。必须更改依赖于集合中固定偏移量的任意代码,以考虑集合中的非元素节点(例如空白等文本节点)。
Beta 2
HtmlElement myHtmlElement = someOtherHtmlElement.Children[5];
发行版本
HtmlElement myHtmlElement = (HtmlElement)someOtherHtmlElement.Children[5]; //assuming the desired element is still at offset 5
影响的对象:使用 visualstatemanager 的 Silverlight 2 应用程序。
VisualTransition.Duration 已更改为 VisualTransition.GeneratedDuration。此值现在将只影响生成的过渡,而不影响 VisualTransition.Storyboard。
示例:
在此处所示的 XAML 中,“pressed”->“normal”过渡的 VSM 生成的动画将在 1 秒钟内创建。具有蓝色 ColorAnimation 的显式过渡 Storyboard 所需时间仍为 2 秒钟。
<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 应针对 ControlTemplate 或 UserControl 的可视化元素根设置,而不应针对 Control/UserControl 本身设置。在下面的示例中,对 Grid(即 ControlTemplate 的可视化元素根)设置自定义可视状态管理器。
<ControlTemplate targettype="local:CheckBox"> <Grid x:Name="RootElement" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent"> <vsm:visualstatemanager.Customvisualstatemanager> <local:Myvisualstatemanager> </vsm:visualstatemanager.Customvisualstatemanager> ... </Grid> </ControlTemplate>
影响的对象:使用 HtmlPage.UnregisterScriptableObject 的应用程序。
需要修复
作为使用 HtmlPage.UnregisterScriptableObject 的替代方案,开发人员现在可以将相同的脚本注册项重新用于 RegisterScriptableObject。这使开发人员可以更改与可编写脚本的入口点关联的基础托管对象。
影响的对象:使用 ContentPresenter 或 ContentControl 类的 Silverlight 2 托管代码。
以下属性已从 ContentPresenter 和 ContentControl 中移除:
-
TextAlignment
-
Textdecorations
-
textwrapping
影响的对象:使用 OpenFileDialog 的 Silverlight 2 应用程序。
-
正在移除 System.Windows.FileDialogFileInfo 类型。现在将通过其基 System.IO.FileInfo 类型将其功能公开给 Silverlight 沙盒中的透明代码。
-
System.Windows.Controls.OpenFileDialog 具有几个使用和公开 FileDialogFileInfo 的属性。正在将它们修改为返回 FileInfo 类型。
需要修复
Beta 2
// Returns a File object for the selected file. If multiple files are selected,returns the first selected file public FileDialogFileInfo SelectedFile { get; } // Returns a collection of File objects for the selected files public IEnumerable<FileDialogFileInfo> SelectedFiles { get; }
发行版本
// Returns a File object for the selected file. If multiple files are // selected,returns the first selected file public FileInfo File { get; } // Returns a collection of File objects for the selected files public IEnumerable<FileInfo> Files { get; }
具有此更改的 OpenFileDialog 使用示例:
openFileDialog = new System.Windows.Controls.OpenFileDialog(); openFileDialog.Multiselect = false; openFileDialog.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"; bool? retval = ofd.ShowDialog(); if (retval != null && retval == true) { // Get the filename string filename = openFileDialog.File.Name; // Open the file System.IO.Stream filestream = openFileDialog.File.OpenRead(); // Do something with the filestream // Close it }
影响的对象:仅限使用此功能组合的 Silverlight 2 应用程序:
-
在与宿主 HTML 页不同的域中部署 XAP,并且
-
在根元素上指定 ExternalCallersFromCrossDomain=”FullAccess” 的应用程序清单 (AppManifest.xaml) 受影响。
在跨域应用程序部署方案中省略了任意脚本的以下功能:沿元素树传递、注册事件并获取事件通知以及从脚本使用 Silverlight 1.0 Downloader。应用程序清单以前支持应用程序作者指定值为 NoAccess(跨域中的默认值)、ScriptableOnly 和 FullAccess 的 ExternalCallersFromCrossDomain 属性。已移除对 FullAccess 选项的支持。
以前依赖于 FullAccess 选项的很多功能现在可以通过可编写脚本的对象功能实现,并且不会给您增加多少工作量。
影响的对象:使用 System.Windows.browser.HtmlWindow 的代码,该代码要求指向同一 DOM 窗口的两个 HtmlWindow 引用的计算结果为 true。当该代码在 Mac 的 Safari 2 或 Safari 3 上运行时,现在将返回 false。
例如:
-
使用一个 iframe 创建页
-
使用桥检索对该 iframe 的两个引用:
-
HtmlWindow one = document.GetElementById(“myIframe”);
-
HtmlWindow two = document.GetElementById(“myIframe”);
-
由于此更改,以下比较现在在 Safari 2/3 Mac 上将返回 false:
-
bool areEqual = (one == two);
不需要修复
如果您依赖于 Address 属性,可以通过以下方式解决此重大更改带来的问题:
Beta 2
void Callback(object sender,DownloadStringCompletedEventArgs args) { DebugPrint(args.Address.ToString()); } void MakeCall(Uri uri,object userState) { webClient.DownloadStringAsync(uri,userState); }
发行版本
class DownloadState { public DownloadState() {} public Uri Address; public object ActualUserState; } void Callback(object sender,DownloadStringCompletedEventArgs args) { DownloadState userState = (DownloadState)args.UserState; DebugPrint(userState.Address.ToString()); } void MakeCall(Uri uri,object userState) { Uri absoluteUri = uri; if (absoluteUri.IsAbsoluteUri == false) { absoluteUri = new Uri(new Uri(webClient.BaseAddress),absoluteUri); } DownloadState downloadState = new DownloadState(); downloadState.Address = absoluteUri; downloadState.ActualUserState = userState; webClient.DownloadStringAsync(uri,downloadState); }
您可以不再创建下表中所列的对象,因为它们的关联构造函数已变为内部的:
-
SizeChangedEventArgs
-
TextChangedEventArgs
-
DownloadProgressEventArgs
-
ExceptionRoutedEventArgs
-
KeyEventArgs
-
MouseButtonEventArgs
-
MouseEventArgs
-
StartupEventArgs
-
Expression
-
GeneralTransform
-
Geometry
-
ImageSource
-
PathSegment
-
SetterBase
-
Transform
-
BindingExpressionBase
-
InputMethod
对于此处所示的方法/构造函数,我们将不再检查空参数。这样,使用空参数将导致 NullReferenceException。在以前的 Silverlight 内部版本中,使用空参数将导致引发 ArgumentNullException。这在功能上没有变化,只是引发的异常类型变了。
以前在 XAML 中可以创建由 Silverlight 运行时定义的某些类,即使它们不具有可用的构造函数。由于此更改,今后您不能在 XAML 中实例化这些类。
已不能在 XAML 中创建这些类(它们仅具有内部构造函数):
-
TriggerCollection
-
InlineCollection
-
RowDeFinitionCollection
-
ColumnDeFinitionCollection
-
RoutedEventARgs
-
MouseButtonEventArgs
-
KeyEventARgs
-
ErrorEventArgs
-
UIElementCollection
-
Downloader
-
InternalWebRequest
-
MultiScaleSubImageCollection
-
MediaAttribute
-
MediaAttributeCollection
-
ExceptionROutedEventArgs
-
DownloadProgressEventArgs
-
StartupEventArgs
-
TextBoxBase
-
TextBoxView
-
TextChangedEventArgs
-
RuntimeHostEventArgs
-
SizeChangedEventArgs
-
RenderingEventArgs
-
ItemCollection
-
CorePropertyChangedEventArgs
-
IsEndabledChangedEventARgs
-
TypeProxy
-
ManagedobjectReference
-
AutomationPropertiesEnum
-
DependencyPropertyProxy
影响的对象:将影响使用 HTTP 轮询双工通道的任何应用程序。
-
已将服务器端的 PollTimeout 设置(PollingDuplexHttpBinding 和 PollingDuplexBindingElement)重命名为 ServerPollTimeout
-
已将 PollingDuplexBindingElement 上的 PollTimeout 设置(客户端)重命名为 ClientPollTimeout。
-
已删除 PollingDuplexHttpBinding 上的 PollTimeout 设置(客户端)。在大多数情况中,您不必更改此项。如果需要进行更改,可以通过 PollingDuplexBindingElement 的 ClientPollTimeout 来实现。
-
已从非 Silverlight(服务器端)轮询双工程序集删除客户端支持(这意味着 BuildChannelFactory 将引发 NotSupportedException)。在原始发行版本中,轮询双工的客户端必须是 Silverlight(并且服务器端必须是常规 .NET Framework,但是此限制已不应用于 Beta 2 中)。
-
各种无效消息过去通常由双工堆栈忽略,现在将拒绝它们。
-
如果在 SOAP 调用期间遇到任何 HTTP 错误(404、500 等),现在将引发 CommunicationException 而非 ProtocolException。
影响的对象:通过 COM API 在本机承载 Silverlight 2 的应用程序。
-
get_OnSourceDownloadComplete
-
get_OnSourceDownloadProgressChanged
-
get_SplashScreenSource
-
put_OnSourceDownloadComplete
-
put_OnSourceDownloadProgressChanged
-
put_SplashScreenSource
此外,还要将 LoadRuntime 函数移到 IXcpControl2。
-
UIElement.HitTest 方法已移到 VisualTreeHelper 类并重命名为 VisualTreeHelper.FindElementsInHostCoordinates。
-
DependencyPropertyChangedEventHandler 委托类型已从 System.Windows.Controls 移到 System.Windows 命名空间。
-
默认情况下,Control.IsTabStop 为 true。现在,所有 Control 派生类(直接或间接派生)都已将 IsTabStop 设置为 true(UserControl、HyperlinkButton、ScrollViewer 和 ListBox 除外)。
-
对于每个来自桌面框架的接口协定,WebRequest.RegisterPrefix() 现在在失败时将返回 false 而非引发异常。
-
Deployment.PartProperty 现在是只读的。
-
Deployment.EntryPointAssemblyProperty 现在是只读的。
-
Deployment.EntryPointTypeProperty 现在是只读的。
-
Deployment.RuntimeVersionProperty 现在是只读的。
-
Deployment.ExternalCallersFromCrossDomainProperty 现在是只读的。
-
Thumb.IsDragging 现在是只读的。
-
Slider.IsFocused 现在是只读的。
-
ButtonBase.IsFocused 现在是只读的。
-
ButtonBase.IsMouSEOver 现在是只读的。
-
ButtonBase.Ispressed 现在是只读的。
-
ToolTipService.GetToolTip 现在为私有。
-
Setter.PropertyProperty 现在是内部的。请使用 CLR 属性来替代 DependencyProperty。
-
Slider.UpdateTrackLayout() 现在是内部的。
-
Slider.OnorientationChanged() 现在是内部的。
-
Slider.OnIsFocusChanged(DependencyPropertyChangedEventArgs e) 现在是内部的。
-
ComboBox.get_IsSelectionActive() 现在是内部的。
-
ComboBox.ScrollIntoView(Int32 index) 现在是内部的。
-
ComboBox.get_SelectionBoxItemTemplate() 现在返回 System.Windows.DataTemplate。
-
PasswordBox.SelectionChanged 现在为私有。
-
MouseEventArgs.Handled 已移到 MouseButtonEventArgs。
-
rendertargetBitmap 已重命名为 HostingrendertargetBitmap 并从 System.Windows.Media.Imaging 移到命名空间 System.Windows.Interop。
-
AutomationPeer 构造函数现在受到保护。
-
TriggerActionCollection.Item 现在使用 System.Windows.TriggerAction 而非 System.Windows.Media.Animation.BeginStoryboard。
-
TriggerCollection.Item 现在使用 System.Windows.TriggerBase 而非 System.Windows.EventTrigger。
-
ITableItemProvider 和 ITableProvider 现在从 IGridItemProvider 和 IGridProvider 派生。
-
KeyboardNavigation 类现在是内部的。
-
InlineCollection 构造函数变为内部的。
-
ItemCollection 构造函数变为内部的。
-
UIElementCollection 构造函数变为内部的。
-
TriggerCollection 构造函数变为内部的。
-
Ink.stroke 构造函数已更改为 ctor(System.Windows.Input.StylusPointCollection)。
-
CanConvertFrom(Type sourceType) 已将其签名更改为 CanConvertFrom(ITypeDescriptorContext context,Type sourceType)。
-
CanConvertTo(Type destinationType) 已将其签名更改为 CanConvertTo(ITypeDescriptorContext context,Type destinationType)。
-
ConvertFrom(object value) 已将其签名更改为 ConvertFrom(ITypeDescriptorContext context,CultureInfo culture,object value)。
-
ConvertFromString(string text) 现在为 ConvertFrom(ITypeDescriptorContext context,object value),其中的值为字符串类型。
-
ConvertTo(object value,Type destinationType) 已将其签名更改为 ConvertTo(ITypeDescriptorContext context,object value,Type destinationType)。
-
ConvertToString(object value) 现在为 ConvertTo(ITypeDescriptorContext context,Type destinationType),其 destinationType 为字符串类型。
-
ItemCollection 构造函数已不可用,因此将不再编译尝试直接实例化 ItemCollection 的任何代码。此类假定为仅在 ItemsControl 内进行实例化。
-
Control.OnIsEnabledChanged 已移除。现在将 IsEnabledChanged 用于扩展控件。
-
DownloadProgressEventHandler 已移除。
-
已移除以下转换器:
-
TextdecorationCollectionConverter
-
FontStretchConverter
-
FontStyleConverter
-
FontWeightConverter
-
FontFamilyConverter
-