WpfToolkit DataGrid 在 Windows Phone 7 中不起作用 [英] WpfToolkit DataGrid does not work in Windows Phone 7

查看:27
本文介绍了WpfToolkit DataGrid 在 Windows Phone 7 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<Grid x:Name="LayoutRoot" Background="#FF1F1F1F" Width="960"><Grid x:Name="TitleGrid"><TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextPageTitle2Style}"/></网格><wtk:DataGrid></wtk:DataGrid></网格></用户控件>

该项目编译良好,但在尝试加载此控件时在运行时崩溃.到目前为止,我得到的最好线索来自 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 context, IReflectable`1 成员, ITypeMetadata attributeType, Boolean merge, AttributeMergeCache& cache)在 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 提供程序、Boolean childrenAsString)在 MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)在 MS.Internal.Design.Markup.XmlElement.ConvertChildrenToXaml(XamlElement 结果、PrefixScope 范围、IParseContext 上下文、IMarkupSourceProvider 提供程序、Boolean childrenAsString)在 MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)在 MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.ParseElementFromSkeleton(XamlParseContext 上下文,SkeletonNode 节点,XamlElement 父级,布尔 fullElement)在 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 sender, MessageKey key, MessageArguments args)在 Microsoft.Windows.Design.DocumentModel.MarkupProducer.Microsoft.Windows.Design.DocumentModel.IDocumentTreeConsumer.HandleMessage(DocumentTreeCoordinator sender, MessageKey key, MessageArguments args)在 Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.SendMessage[T](MessageKey`1 key, T args, Boolean 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(Delegate callback, Object args, Int32 numArgs)在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,委托方法,对象参数,Int32 numArgs,委托 catchHandler)

解决方案

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

既然我把所有的努力都放在了这个问题上,我会把问题和答案作为 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

I am trying to use WpfToolkit DataGrid in Windows Phone 7 project (Silverligt 4) and it's not working. Here is the 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>

The project compiles fine but crashes at runtime trying to load this control. The best clue I got so far is from Visual Studio Designer. Once I add wtk:DataGrid to the control the visual designer does not load and below is the exception it displays.

Could it be that WpfToolkit relies on PresentationFramework.dll and it's not available in SL4?

System.Reflection.Adds.UnresolvedAssemblyException
Type universe cannot resolve assembly: PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
   at System.Reflection.Adds.AssemblyProxy.GetResolvedAssembly()
   at System.Reflection.Adds.AssemblyProxy.get_FullName()
   at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.PrepareAttributes(Reflectable`1 reflectableAssembly)
   at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.PrepareAttributes(Reflectable`1 reflectableType)
   at MS.Internal.Metadata.ClrType.GetAttributes[T](ReflectionMetadataContext context, IReflectable`1 member, ITypeMetadata attributeType, Boolean merge, AttributeMergeCache& cache)
   at MS.Internal.Metadata.ClrMember`1.GetLocalAttributes(ITypeMetadata attributeType)
   at MS.Internal.Design.Metadata.Xaml.XamlType.GetSpecialProperty(Int32 idx, PropertyIdentifier pid)
   at MS.Internal.Design.Metadata.Xaml.XamlType.get_ContentProperty()
   at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.GetContentProperty(ITypeMetadata sourceType)
   at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensions.GetContentProperty(ITypeMetadata source)
   at MS.Internal.Design.Metadata.ReflectionTypeNode.get_ContentProperty()
   at MS.Internal.Design.Markup.XmlElement.CalcChildWhitespaceImportant(XamlElement element)
   at MS.Internal.Design.Markup.XmlElement.ConvertChildrenToXaml(XamlElement result, PrefixScope scope, IParseContext context, IMarkupSourceProvider provider, Boolean childrenAsString)
   at MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)
   at MS.Internal.Design.Markup.XmlElement.ConvertChildrenToXaml(XamlElement result, PrefixScope scope, IParseContext context, IMarkupSourceProvider provider, Boolean childrenAsString)
   at MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)
   at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.ParseElementFromSkeleton(XamlParseContext context, SkeletonNode node, XamlElement parent, Boolean fullElement)
   at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.UpdateSkeleton(IDamageListener listener)
   at Microsoft.Windows.Design.DocumentModel.Trees.MarkupDocumentTreeManager.Update()
   at Microsoft.Windows.Design.DocumentModel.MarkupProducer.Update()
   at Microsoft.Windows.Design.DocumentModel.MarkupProducer.HandleMessage(DocumentTreeCoordinator sender, MessageKey key, MessageArguments args)
   at Microsoft.Windows.Design.DocumentModel.MarkupProducer.Microsoft.Windows.Design.DocumentModel.IDocumentTreeConsumer.HandleMessage(DocumentTreeCoordinator sender, MessageKey key, MessageArguments args)
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.SendMessage[T](MessageKey`1 key, T args, Boolean isPrivateMessage)
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.QueuedMessage`1.Microsoft.Windows.Design.DocumentModel.IQueuedMessage.Invoke()
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.ProcessQueuedMessages(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

解决方案

Just when I was about to post the question, the StackOverflow tags auto-suggest showed that there is Silverlight Toolkit. Clearly this is what I should use.

Since I put all that effort into the question I will leave the question and the answer as a testemant to StackOverflow awesomeness in auto-answering my question.

EDIT You need Silverlight 3 Toolkit binaries to use DataGrid. You need to add these four references to the project:

  1. System.ComponentModel.DataAnnotations.dll
  2. System.Windows.Controls.Data.dll
  3. System.Windows.Controls.Data.Input.dll
  4. System.Windows.Data.dll

这篇关于WpfToolkit DataGrid 在 Windows Phone 7 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆