4

我正在尝试DataGrid在 Windows Phone 7 项目(Silverligt 4)中使用 WpfToolkit,但它不起作用。这是 XAML:

<UserControl x:Class="SilverlightControls.Grid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:wtk="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" Background="#FF1F1F1F" Width="960">
        <Grid x:Name="TitleGrid">
            <TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextPageTitle2Style}"/>
        </Grid>
        <wtk:DataGrid>
        </wtk:DataGrid>
    </Grid>
</UserControl>

该项目编译良好,但在运行时尝试加载此控件时崩溃。到目前为止,我得到的最好的线索来自 Visual Studio Designer。一旦我添加wtk:DataGrid到控件,视觉设计器就不会加载,下面是它显示的异常。

会不会是 WpfToolkit 依赖于 PresentationFramework.dll 而它在 SL4 中不可用?

System.Reflection.Adds.UnresolvedAssemblyException
类型 Universe 无法解析程序集:PresentationFramework,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35。
   在 System.Reflection.Adds.AssemblyProxy.GetResolvedAssembly()
   在 System.Reflection.Adds.AssemblyProxy.get_FullName()
   在 Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.PrepareAttributes(Reflectable`1 reflectableAssembly)
   在 Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.PrepareAttributes(Reflectable`1 reflectableType)
   在 MS.Internal.Metadata.ClrType.GetAttributes[T](ReflectionMetadataContext 上下文,IReflectable`1 成员,ITypeMetadata attributeType,布尔合并,AttributeMergeCache& 缓存)
   在 MS.Internal.Metadata.ClrMember`1.GetLocalAttributes(ITypeMetadata attributeType)
   在 MS.Internal.Design.Metadata.Xaml.XamlType.GetSpecialProperty(Int32 idx,PropertyIdentifier pid)
   在 MS.Internal.Design.Metadata.Xaml.XamlType.get_ContentProperty()
   在 Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.GetContentProperty(ITypeMetadata sourceType)
   在 Microsoft.Windows.Design.Metadata.Xaml.XamlExtensions.GetContentProperty(ITypeMetadata 源)
   在 MS.Internal.Design.Metadata.ReflectionTypeNode.get_ContentProperty()
   在 MS.Internal.Design.Markup.XmlElement.CalcChildWhitespaceImportant(XamlElement 元素)
   在 MS.Internal.Design.Markup.XmlElement.ConvertChildrenToXaml(XamlElement 结果,PrefixScope 范围,IParseContext 上下文,IMarkupSourceProvider 提供程序,布尔 childrenAsString)
   在 MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent,PrefixScope parentScope,IParseContext 上下文,IMarkupSourceProvider 提供程序)
   在 MS.Internal.Design.Markup.XmlElement.ConvertChildrenToXaml(XamlElement 结果,PrefixScope 范围,IParseContext 上下文,IMarkupSourceProvider 提供程序,布尔 childrenAsString)
   在 MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent,PrefixScope parentScope,IParseContext 上下文,IMarkupSourceProvider 提供程序)
   在 MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.ParseElementFromSkeleton(XamlParseContext 上下文,SkeletonNode 节点,XamlElement 父级,布尔全元素)
   在 MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.UpdateSkeleton(IDamageListener 监听器)
   在 Microsoft.Windows.Design.DocumentModel.Trees.MarkupDocumentTreeManager.Update()
   在 Microsoft.Windows.Design.DocumentModel.MarkupProducer.Update()
   在 Microsoft.Windows.Design.DocumentModel.MarkupProducer.HandleMessage(DocumentTreeCoordinator 发件人,MessageKey 键,MessageArguments 参数)
   在 Microsoft.Windows.Design.DocumentModel.MarkupProducer.Microsoft.Windows.Design.DocumentModel.IDocumentTreeConsumer.HandleMessage(DocumentTreeCoordinator 发件人,MessageKey 键,MessageArguments 参数)
   在 Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.SendMessage[T](MessageKey`1 键,T args,布尔 isPrivateMessage)
   在 Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.QueuedMessage`1.Microsoft.Windows.Design.DocumentModel.IQueuedMessage.Invoke()
   在 Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.ProcessQueuedMessages(对象状态)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象 args,Int32 numArgs)
   在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,委托方法,对象 args,Int32 numArgs,委托 catchHandler)

4

1 回答 1

3

就在我要发布问题时,StackOverflow 标签自动建议显示有Silverlight Toolkit。显然这是我应该使用的。

因为我把所有的精力都放在了这个问题上,所以我将把问题和答案作为 StackOverflow 在自动回答我的问题方面的出色表现的证明。

编辑您需要 Silverlight 3 Toolkit 二进制文件才能使用 DataGrid。您需要将这四个引用添加到项目中:

  1. System.ComponentModel.DataAnnotations.dll
  2. System.Windows.Controls.Data.dll
  3. System.Windows.Controls.Data.Input.dll
  4. System.Windows.Data.dll
于 2010-03-23T11:47:27.507 回答